aspose file tools*
The moose likes Beginning Java and the fly likes convert datetime from EST to PST Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "convert datetime from EST to PST" Watch "convert datetime from EST to PST" New topic
Author

convert datetime from EST to PST

Dave Bosky
Ranch Hand

Joined: Dec 16, 2003
Posts: 72
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
Jeremy Wilson
Ranch Hand

Joined: Feb 18, 2003
Posts: 166
I believe if you create a GregorianCalendar object you can specify the timezone that the object will return. Create the object using EST and then change the timezone to PST for the new value.


Jeremy Wilson
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
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.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
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
Dave Bosky
Ranch Hand

Joined: Dec 16, 2003
Posts: 72
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?

Thanks Again,
Dave
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
if you only care about EST to PST, GregorianCalendar is enough
try the following:

[ March 25, 2004: Message edited by: chi Lin ]
 
 
subject: convert datetime from EST to PST