Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting to UTC time zone

 
Rajesh Pattabi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i need to convert UTC my code is

this code does not give correct output for input date 03/13/2011 02:00
 
Tim Moores
Bartender
Posts: 2947
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the output? What do you think it should be instead?
 
Rajesh Pattabi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i give 03/13/2011 08:00........ it should return 03/12/2011 01:00 that is input date -7hrs is correct for UTC conversion but for DST times it converts -8 instead -7.
 
Rajesh Pattabi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores,
Actually i am trying to convert date and time to UTC. My client local timezone is US/Pacific. this code works fine for all the cases if i give 03/20/2012 10:00 it converts correctly and returned 03/20/2012 03:00 but for this DST when i give input for 03/13/2011 08:00 it should return 03/12/2011 01:00 but this code returning 03/12/2011 00:00
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajesh Pattabi wrote:Tim Moores,
Actually i am trying to convert date and time to UTC. My client local timezone is US/Pacific. this code works fine for all the cases if i give 03/20/2012 10:00 it converts correctly and returned 03/20/2012 03:00 but for this DST when i give input for 03/13/2011 08:00 it should return 03/12/2011 01:00 but this code returning 03/12/2011 00:00


That doesn't sound right.

You claim you're going TO UTC FROM US/Pacific. However, when you say "if i give 03/20/2012 10:00 it converts correctly and returned 03/20/2012 03:00", that means you're going the opposite direction from what you're claiming.

And an input of 03/13/2011 08:00 in either TZ is not 03/12/2011 01:00 or 03/12/2011 00:00 as you claim.

The correct way do to this is to simply set the DateFormat's TZ to the one you want to display in. You don't do any conversion math with offsets, and you don't set the Calendar's "hours" field. Note that regardless of which TZ you're using for your display, you're viewing the same instant in time, and hence the same DATE object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic