aspose file tools*
The moose likes Java in General and the fly likes DST in Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "DST in Java?" Watch "DST in Java?" New topic
Author

DST in Java?

Bret Waldow
Ranch Hand

Joined: Aug 04, 2000
Posts: 59
Hello,

I'm in New Zealand, and we are currently observing Daylight Savings Time.

I am using this:
DateFormat DF = new SimpleDateFormat( "EEE dd MMM yyyy hh:mm aa zz : zzzzzz" );

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.

Cheers,
Bret
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
Not quite what you're asking for, but maybe this helps: http://faq.javaranch.com/java/JavaDatesFaq#dst

But then, there was a change in DST in NZ not too long ago - is the JRE you're using recent enough to know about that?


Ping & DNS - my free Android networking tools app
Bret Waldow
Ranch Hand

Joined: Aug 04, 2000
Posts: 59
I think the JVM is up to date:

C:\Documents and Settings\developers>java -version
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)

I'll read the other link, and I'd be happy to yet hear from anyone that can address what to me is a rather incomprehensible state of affairs...
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

What happens when you run TimeZone.getDefault?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
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.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
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.
Bret Waldow
Ranch Hand

Joined: Aug 04, 2000
Posts: 59
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.

Thanks for the help so far.

Cheers,
Bret
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Check what version that 1.5 JVM is, it may not have had the timezone change for NZ applied to it, nice to see another Kiwi on board BTW
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DST in Java?