• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Date Format

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something like this (highly inspired by Barry's post) should work.
 
selvi family
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all of U....My prob is solved...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic