• Post Reply Bookmark Topic Watch Topic
  • New Topic

Time conversion  RSS feed

 
Adam Teg
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does yyyyMMddHHmmssZ in SimpleDateFormat of 20070617000615+0000 return 2007-06-16T19:06:15. Shouldn't it return - 2007-06-17....

-Thanks
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you're using the yyyyMMddHHmmssZ format to parse the input 20070617000615+0000, then using a different DateFormat to display the parsed Date? Because yyyyMMddHHmmssZ doesn't have any hyphens or the letter T. This second format doesn't seem to include the time zone, which is probably your problem. I would guess that you're in GMT-5, most likely Central Daylight Time in the US (or whatever it's called in Canada), and your format is correctly displaying the input time in your local time zone. You need to realize that these two times represent exactly the same time:

2007-06-17T00:06:15 in GMT
2007-06-16T19:06:15 in GMT-5

If you want to display the time in GMT rather than you local time zone, you should use the DateFormat's setTimeZone() to specify which time zone to use. E.g.

dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
 
Adam Teg
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!