File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Converting to UTC time zone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Converting to UTC time zone" Watch "Converting to UTC time zone" New topic
Author

Converting to UTC time zone

Rajesh Pattabi
Greenhorn

Joined: Apr 03, 2012
Posts: 9
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
Rancher

Joined: Sep 21, 2011
Posts: 2408
What is the output? What do you think it should be instead?
Rajesh Pattabi
Greenhorn

Joined: Apr 03, 2012
Posts: 9
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

Joined: Apr 03, 2012
Posts: 9
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting to UTC time zone