Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.6: Fix errors with certain timezones in Java System 10.6
Java on MacOS X 10.6 has some problems with certain timezones. This problem only affects Java programs, but will cause any Java programs to use incorrect dates. For example, any cities/towns/villages in southern Ontario (locations using "America/Toronto") will find their Java apps reporting an offset of five minutes behind GMT.

The solution is to explicitly specify an alternative location that doesn't have problems. For those in southern Ontario, Montreal works fine. To see if you have this problem, perform the following steps:
  1. Copy the following text to a file called tz.java in your home directory:
    class tz {
      public static void main(String[] args) {
        java.util.TimeZone tz = java.util.TimeZone.getDefault();
        System.out.println("Timezone offset from UTC reported as " +
    	(tz.getRawOffset() / 1000 / 60) + " minutes");
        if(tz.getRawOffset() % (15 * 60 * 1000) != 0) {
    	System.out.println("Warning: not a multiple of quarter-hours");
        }
        System.out.println(new java.util.Date());
        System.out.println(tz);
      }
    }
    
  2. javac tz.java


After compiling, run the program with java tz. Check that the information reported is correct for your area. Incorrect timezones seem to report an offset from UTC measured in minutes rather than hours or half-hours, and have an id with GMT with an offset rather than a city name. For example, an incorrect output:
Timezone offset from UTC reported as -5 minutes
Warning: not a multiple of quarter-hours
Tue Oct 20 16:02:32 GMT-00:05 2009
sun.util.calendar.ZoneInfo[id="GMT-00:05",offset=-300000,
  dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
A correct output should look something like:
Timezone offset from UTC reported as -300 minutes
Tue Oct 20 12:17:40 EDT 2009
sun.util.calendar.ZoneInfo[id="America/Montreal",offset=-18000000,
  dstSavings=3600000,useDaylight=true,transitions=231,
  lastRule=java.util.SimpleTimeZone[id=AmericaMontreal,offset=-18000000,
  dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,
  startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,
  endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]
If the output doesn't look correct, then you'll need to set a different timezone location with System Preferences » Date & Time » Time Zone. Look at the files in /usr/share/zoneinfo for an appropriate city near you. You can access this directory from the Finder by using Go » Go to Folder, and then providing the path. I've logged this problem with Apple.

[robg adds: I tested this one, and it seems to work. My timezone offset was reported in minutes, but it's the correct number of minutes.]
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (9 votes cast)
 
[6,177 views]  

10.6: Fix errors with certain timezones in Java | 3 comments | Create New Account
Click here to return to the '10.6: Fix errors with certain timezones in Java' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: Fix errors with certain timezones in Java
Authored by: Fanglord on Nov 03, '09 09:58:32AM

For a second, I thought this hint only applied to people living on a certain island in Indonesia... :)



[ Reply to This | # ]
10.6: Fix errors with certain timezones in Java
Authored by: mbloore on Dec 09, '09 09:56:28PM

i compiled tz.java, but it always reports my true time zone (-300 minutes) whatever i set in date/time prefs. but vuze (a java program) thinks i'm at -5 minutes. however, setting my location to montreal fixed vuze.



[ Reply to This | # ]
10.6: Fix errors with certain timezones in Java
Authored by: lovespell88 on Dec 04, '10 08:24:55AM
It's true that there are certain problems with Java when speaking of timezones, but isn't it only recent that they've released this timezone updater tool to fix java issue like this? The TZUpdater tool allows you to update installed Java Development Kit (JDK) and Java Runtime Environment (JRE) software with more recent timezone data, to accommodate daylight saving time (DST) changes in different countries. It's very convenient because it provides a means of updating timezone data while leaving other system configuration and dependencies unchanged.

[ Reply to This | # ]