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.