I need to convert a date time from EST to PST time. ex: 3/24/2004 09:00:00 -> 3/24/2004 06:00:00 I thought I could just subtract 3 hours and be done but the date could change after subtracting 3 hours from 1AM (01:00:00) and that threw in another problem... Are any classes I that do something similiar to what I need? Any examples would be excellent as well.... Thanks, Dave
Well, you don't necessarily have to subtract 3 hours; just set the hours value to 3 less:
I think that should work. The whole mod thing is so if it turns out to be a negative number, we actually want the value set to 24 - value. See if this will work for you. My only other suggestion is the use of java.util.TimeZone and it's methods to compute differences of times between different time zones and UTC; but it seems your non-change-of-day constraint makes some of this a bit akward.
you can represent the EST date object in term of mill seconds then use setTimeInMillis(currentTimeMill - 60*60*3000) to get the PST time. this way, the new date will adjust itself automatically. [ March 25, 2004: Message edited by: chi Lin ]
not so smart guy still curious to learn new stuff every now and then
Joined: Dec 16, 2003
Actually I need the date to change with the time. If I've got 03/10/2004 01:00:00 EST and when converting to PST I need the date to change if necessary. Example 03/10/2004 01:00:00 EST => 03/09/2004 22:00:00 PST. So which class would be better to use timezone or gregorian calendar?