Handle TimeZone changes at runtime?

J

Joe

I am working on a cross platform (Windows/Solaris/HP) Java 1.4.2_03
application which needs to display the current system time zone to the
user.

I was planning to use the output of
java.util.TimeZone.getDefault().toString() to display to the user. I
don't see another method which will tell me what the current system
time zone is.

The problem is that while my program is running and I go to the
Windows "Date and Time Properties" screen and change the system time
zone, the output of the above call does not seem to update. It always
contains the original time zone name. If I kill and restart my app I
can then see the new TimeZone. I also tried checking the System
property user.timezone but it doesn't seem to update either.

I looked at the source for TimeZone.getDefault() and it seems to set a
static within the TimeZone class the 1st time it is called. It also
uses a private native call to getSystemTimeZoneID() but I can't call
that. The static TimeZone value set the 1st time called seems to be
the problem but is there some way around this? I didn't find anything
useful anywhere else in the TimeZone, SimpleTimeZone, Calendar, etc.
classes.

I am currently using Windows XP SP1 if it matters.

Any ideas?

Thanks,

-Joe
 
R

Roedy Green

The problem is that while my program is running and I go to the
Windows "Date and Time Properties" screen and change the system time
zone, the output of the above call does not seem to update. It always
contains the original time zone name. If I kill and restart my app I
can then see the new TimeZone. I also tried checking the System
property user.timezone but it doesn't seem to update either.

I think you are hosed here. The timezone property gets by a native
method when you first start. Windows does not notify Java if it
changes and Java does not poll every time.

You need some JNI. I could roll you one for $100.00 US.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top