Strictly speaking, the time ISN'T shifting. 15:00 hours in New York
is the same time as 12:00 in Seattle.
POJO store time as # of ms since 1/1/70 0:00:00 UTC. When converted
to a string, the JVM applies the default TimeZone which is based upon
the configuration of the host OS.
Trick 1: Convert to String before serializing to client.
Trick 2: Add TimeZone information to the serialized class.
Trick 3: Hard-Code "GMT" or whatever into the applet.
Below is a code fragment which shows how the same Date object can
print two different times for two different timezones without changing
its value.
-----------------------------------------------------------------
import java.text.*;
import java.util.*;
public class z
{
public static void main(String args[])
{
Date d = new Date();
System.out.println(d.getTime());
DateFormat df = DateFormat.getDateTimeInstance();
df.setTimeZone(TimeZone.getTimeZone("EST5EDT"));
System.out.println(df.format(d));
df.setTimeZone(TimeZone.getTimeZone("PST8PDT"));
System.out.println(df.format(d));
System.out.println(d.getTime());
}
}
$ java z
1116357599329
17-May-05 3:19:59 PM
17-May-05 12:19:59 PM
1116357599329
On 17/05/05, Brian Bonner <brian.bonner@xxxxxxxxxxxx> wrote:
> Guys, I have an app that does Java serialization of POJOs between a
> client and a server. The POJOs contain a date which stores the time in
> ms since 1/1/70. The app works fine with one exception -- the date of
> the pojo displayed in the applet in one time zone is different than the
> date of the pojo displayed in the applet from a different time zone.
>
> I've talked w/ folks and can only attribute this to the timezone of the
> PC (or the JVM) being set incorrectly. Does anyone else have any
> thoughts on what else might be causing this time shift?
>
> Thanks.
>
> --
> Brian
>
> ---------
> You may unsubscribe from this mailing list
> by sending a blank email addressed to:
> users-unsubscribe@xxxxxxxxxx
>
> --
> Find additional help by sending a blank email
> addressed to:
> users-help@xxxxxxxxxx
>
>
--
Cheers,
Eric Bardes
|