The Time Zone it prints is:
NZST : New Zealand Standard Time
... and the hour reported is off by one.
But we're in Daylight Savings Time. The underlying Windows OS knows it's NZDT, and reports the time correctly.
I've read a bit about various problems and thoughts regarding this, but I can't help but feel I'm missing something. None of what I read appears to address this - most is about converting to other time zones, or comparing times.
Can Java tell what time it is? Why doesn't Java simply print out what the current system time is correctly?
I don't want to parse the time - we might install our application in another machine in another time zone, and I would want/expect it to pick up whether it's currently operating under DST or not in that time zone - the OS can tell.
What am I missing, please? Can this be done, or am I wasting my time trying to solve it?
Thanks for the answer to that last question especially - I have read about various ways to force DST, but that's the point of time zones - we know whether we're in DST already because of the time zone information. I really expect this to be the way it is, and so I expect I have missed something.
It sounds like your understanding is pretty much accurate - in general Java should, and usually does, handle this sort of thing for you. But something's gone wrong in this case.
Where are these Date instances coming from? Are you just using new Date(), for the current time? Or are you getting them from a database, or parsing a file, or something like that? These Dates aren't, say, a few days in the future, when NZDT no longer applies, are they?
Are you doing anything to set the time zone yourself from Java? If so, please show us what. If not, you can probably get correct results by calling
I understand that you want this to be picked up automatically, and it should be. But trying this will help tell us whether the problem is really with the time zone, or somewhere else.
Joined: Mar 05, 2008
The behavior you describe is just what you'd get if the JVM were not sufficiently up-to-date. NZDT used to end on the third Sunday in March, and now it ends on the first Sunday in April. So we're currently in the period where out-of-date time zone info could create this bug.
However, according to this page, the NZ date made it in to JDK 1.6 update 2 (6u2). If you're using 1.6.0_13 (update 13, one assumes) you should already have the latest NZ-specific data. But Sun's inconsistent notation is confusing.
You got the Java version by running java -version from the command line. Are you also running your program from the command line? Or are you running it through a server, IDE, or other intermediary program? If the latter, it's possible that the server/IDE/whatever is actually configured to use a different JDK version than what you get from the command line.
Joined: Aug 04, 2000
I've been pulled off this for a little while but I had time for one experiment.
Using some code a fellow on the Sun forum provided with JVM 1.5, (the default JVM this customer uses), I get 'NZST' when I expect 'NZDT'.
Switching to JVM 1.6, I get 'NZDT' as expected.
Here is the code:
This is run through my Eclipse IDE, so might be something to do with 'compatibility mode' or an improperly updated JVM or...
I'll be back the problem soon, and try to figure out more.