File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Date Format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date Format" Watch "Date Format" New topic
Author

Date Format

selvi family
Ranch Hand

Joined: Nov 26, 2004
Posts: 39
Hi,

I had a doubt in NumberFormat to display the US currency.It was cleared through javaranch.

Now I have a doubt in DateForamt...

I am using Oracle data base to store the date.
In data base the stored date is fetched as "2005-01-06 04:28:42.0"

Is that possible to display the sais date in "Jan 6, 2005" format.

I tried the following code:
sodate is a arraylist:

The datestring variable stores the value "2005-01-06 04:28:42.0"

DateFormat df=DateFormat.getDateInstance(DateFormat.MEDIUM,Locale.US);
Date date2 = df.parse(datestring);
out.println(df.format(date2));

I got the ParseException...

How to solve this..
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Well, you get the value from the DB as a Date object, rather than as a String you then parse. Then you apply the formating you need by defining it in your SimpleDateFormat (read the docs) and calling the format method.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Barry Higgins
Ranch Hand

Joined: Jun 05, 2003
Posts: 89
To get you started you are going to need two SimpleDateFormats:
One to parse the date being passed in

DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");

and one to format the date to the way you want it to look

DateFormat df=new SimpleDateFormat("MMM d, yyyy");

Post back if you are having problems!
Jonas Isberg
Ranch Hand

Joined: Mar 18, 2003
Posts: 118
Something like this (highly inspired by Barry's post) should work.
selvi family
Ranch Hand

Joined: Nov 26, 2004
Posts: 39
Thanks to all of U....My prob is solved...
 
wood burning stoves
 
subject: Date Format