• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DST in Java?

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bret Waldow
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens when you run TimeZone.getDefault?
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic