wood burning stoves*
The moose likes Java in General and the fly likes SimpleDateFormat parse() gives incorrect result 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 » Java in General
Bookmark "SimpleDateFormat parse() gives incorrect result" Watch "SimpleDateFormat parse() gives incorrect result" New topic
Author

SimpleDateFormat parse() gives incorrect result

Preet Dholabhai
Greenhorn

Joined: Jan 24, 2010
Posts: 19
Dfault TimeZone GMT-3.00.
I am parsing new Date("1900/01/01").toString using the parse method of SimpleDateFormat.

The Result i get is
Sun Dec 31 23:15:16 UYT 1899
instead of
Mon Jan 01 00:00:00 UYT 1900

I can't understand why is the result different.

PS: If i change the TimeZone to GMT +5.30 the result is as expected.


Thanks & regards,
Preet
Ravishanker kumar
Ranch Hand

Joined: Jul 20, 2006
Posts: 53
Try with SimpleDateFormate and Local ,

SimpleDateFormat df=new SimpleDateFormat("yyyy/MM/dd",Locale.US);
Date date= df.parse("1900/01/01");
System.out.println("date:"+date);

Regards,
Ravi
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: SimpleDateFormat parse() gives incorrect result