This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

SimpleDateFormat  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello need some help !

i take in a String that looks like timePattern

I just wonder how i change the output format when converting this


if i make a print out on the result now i got Thu Nov 25 00:00:00 CET 2004
if i want for example 2004-11-30 12:33:35 how do i do that.


String timePattern = "yyyy-MM-dd";
SimpleDateFormat formatter = new SimpleDateFormat(timePattern);

Date fe=getDateInstance(formatter);

Date d = null;
try {
d = formatter.parse(publishDate, new ParsePosition(0));
} catch (NullPointerException e) {
}
System.out.print(d) // gives Thu Nov 25 00:00:00 CET 2004
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are printing out the Date object, not the SimpleDateFormat object.
 
Janne ukko
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i want the correct date into the Date varible to send to a function that set a Date varible, how do i do that
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Date object contains an internal representation of the date, so it will have the correct value, regardless of the format you use to enter the date.

For example


Also, have a look at the Sun API Docs
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!