• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Converting to UTC time zone

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic