• 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

Formatting Dates

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Need some help here... I am returning a date field from an oracle query and it returns in the format:
1958-06-11 00:00:00.0
is there a way in java to convert this into 11/06/1958?
Thanks a million!
Cheers,
Wai Meng
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Originally posted by wai meng:
Hi All,
Need some help here... I am returning a date field from an oracle query and it returns in the format:
1958-06-11 00:00:00.0
is there a way in java to convert this into 11/06/1958?
Thanks a million!
Cheers,
Wai Meng


Take a look at SimpleDateFormat.parse(String) and SimpleDateFormat.format(Date).
(http://java.sun.com/j2se/1.4/docs/api/java/text/SimpleDateFormat.html)
Heli
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Wai Meng,
Of course it is possible to format dates into whatever format you want. The easiest way to do this is by using the java.text.SimpleDateFormat class. It gives you the possibility to set the format when creating an instance of the class, while the format(Date d) function returns a String with the date according to the set format.
I wasn't sure if in your case you had an object of type Date or of type String, with the date from the Oracle database. If you have a Date object called dDate, then this is about all you need to do to print the date in your preferred format:

If you have a String with the date in it, say sDate, you'll have to parse it to a Date first, before you can do the above. The parsing can be done with the java.text.SimpleDateFormat too. Though in this case you'll need a second formatter, this time with the format of the Oracle date:

Hope this helps,
Tim
 
wai meng
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the info, I have looked up the reference but an not very sure how to begin to use it... I tried to look for sample codes but to no avail... can someone help?
Thanks again..
 
wai meng
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure did Tim, thanks so much....
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic