• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calendar.getTime() not properly reporting DST?

 
Jeff Harbinson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks.

I have an application that is an hour behind the correct time. It seems as though daylight savings is not being accounted for.

Here's info on the system, java version, and system time:

$ date
Fri Apr 9 13:39:59 CDT 2010

$ java -version
java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.6.1) (6b16-1.6.1-3ubuntu1)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)

$ uname -a
Linux laptop 2.6.31-20-generic #58-Ubuntu SMP Fri Mar 12 04:38:19 UTC 2010 x86_64 GNU/Linux


Here's some debug output from the application regarding Calendar:

Calendar: java.util.GregorianCalendar[time=1270838362927,areFieldsSet=true, areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="SystemV/CST6CDT", offset=-21600000,dstSavings=3600000,useDaylight=true,transitions=276 lastRule=java.util.SimpleTimeZone[id=SystemV/CST6CDT, offset=-21600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=3,startDay=-1, =1,startTime=7200000,startTimeMode=0,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=7200000, endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2010,MONTH=3,WEEK_OF_YEAR=15, WEEK_OF_MONTH=2,DAY_OF_MONTH=9,DAY_OF_YEAR=99,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=2, AM_PM=1,HOUR=0,HOUR_OF_DAY=12,MINUTE=39,SECOND=22,MILLISECOND=927,ZONE_OFFSET=-21600000, DST_OFFSET=0]

Calendar.getTime(): Fri Apr 09 12:39:22 CST 2010

Calendar.getTimeZone(): sun.util.calendar.ZoneInfo[id="SystemV/CST6CDT",offset=-21600000,dstSavings=3600000,useDaylight=true,transitions=276,lastRule=java.util.SimpleTimeZone[id=SystemV/CST6CDT,offset=-21600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=3,startDay=-1,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]


As you can see, Calendar.getTime() is reporting standard time, not daylight time. Can anybody explain why?

Thanks!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a small program that will tell you if the current date and time are in daylight savings of the default timezone of your system:


You're using an OpenJDK 6 version of Java. Do you have the latest updates installed? Sometimes the timezone information is updated in newer versions of Java.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49472
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beware of long lines of code; I have put some space in that long toString() printout otherwise it was too wide for my screen.
 
Jeff Harbinson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper Young wrote:Here's a small program that will tell you if the current date and time are in daylight savings of the default timezone of your system:


You're using an OpenJDK 6 version of Java. Do you have the latest updates installed? Sometimes the timezone information is updated in newer versions of Java.


Here's the output of the above code, which I believe agrees w/ the output I originally posted:

$ java JavaRanch
Is date Mon Apr 12 08:17:34 CST 2010 in daylight savings of timezone Central Standard Time: false

I have the latest time zone data installed on my machine.

So, can somebody explain why Java thinks I'm not using DST, given this?:

$ date
Mon Apr 12 09:20:04 CDT 2010


Thanks!
 
Jeff Harbinson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regardless of the output you see below, I was actually using the Sun JDK, version 1.6.0_17.

I updated to the most recent (1.6.0_19), and DST is properly determined now.




Jeff Harbinson wrote:Hi folks.

I have an application that is an hour behind the correct time. It seems as though daylight savings is not being accounted for.

Here's info on the system, java version, and system time:

$ date
Fri Apr 9 13:39:59 CDT 2010

$ java -version
java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.6.1) (6b16-1.6.1-3ubuntu1)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)

$ uname -a
Linux laptop 2.6.31-20-generic #58-Ubuntu SMP Fri Mar 12 04:38:19 UTC 2010 x86_64 GNU/Linux


Here's some debug output from the application regarding Calendar:

Calendar: java.util.GregorianCalendar[time=1270838362927,areFieldsSet=true, areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="SystemV/CST6CDT", offset=-21600000,dstSavings=3600000,useDaylight=true,transitions=276 lastRule=java.util.SimpleTimeZone[id=SystemV/CST6CDT, offset=-21600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=3,startDay=-1, =1,startTime=7200000,startTimeMode=0,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=7200000, endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2010,MONTH=3,WEEK_OF_YEAR=15, WEEK_OF_MONTH=2,DAY_OF_MONTH=9,DAY_OF_YEAR=99,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=2, AM_PM=1,HOUR=0,HOUR_OF_DAY=12,MINUTE=39,SECOND=22,MILLISECOND=927,ZONE_OFFSET=-21600000, DST_OFFSET=0]

Calendar.getTime(): Fri Apr 09 12:39:22 CST 2010

Calendar.getTimeZone(): sun.util.calendar.ZoneInfo[id="SystemV/CST6CDT",offset=-21600000,dstSavings=3600000,useDaylight=true,transitions=276,lastRule=java.util.SimpleTimeZone[id=SystemV/CST6CDT,offset=-21600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=3,startDay=-1,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]


As you can see, Calendar.getTime() is reporting standard time, not daylight time. Can anybody explain why?

Thanks!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, so it was indeed a case of using an older / alternate JDK which contained outdated or wrong daylight savings information.

(p.s. Please don't quote the whole previous discussion each time you post a response).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic