Duplicate :
|
|
Relates :
|
|
Relates :
|
Hardware: Pentium IV OS: Windows XP Professional SP2 Java version: java version "1.5.0_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05) Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing) Problem: TimeZone.getDefault() returns two different timezones for Windows GMT-12 regarding to the 'Automatically adjust clock for daylight saving changes' is checked and not. When the daylight saving adjustment checkbox is off, java correctly recogizes GMT-12 as "GMT-12:00". But when it's checked on, Pacific/Majuro is returned, whose timezone is GMT+12. Test case: A simple program is provided to re-produce the problem. It can be re-produced always. ////////////////////////////////////////////////////////////// // TestTimeZone.java - BEGIN // ////////////////////////////////////////////////////////////// import java.util.*; public class TestTimeZone { public static void main(String[] args) { System.out.println("timezone is " + TimeZone.getDefault()); System.out.println("time is " + new Date()); } } ////////////////////////////////////////////////////////////// // TestTimeZone.java - END // ////////////////////////////////////////////////////////////// Steps to re-produce: 1. Compile the above program. 2. Select Windows XP timezone as (GMT+10:00) Canberra, Melbourne, Sydney. 3. Un-check the 'Automatically adjust clock for daylight saving changes' checkbox. 4. Change the timezone to (GMT-12:00) International Dateline West. 5. Run the test program. It should give you a similar output like below. It's correct. =========== step 5 output begin =============== timezone is sun.util.calendar.ZoneInfo[id="GMT-12:00",offset=-43200000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null] time is Sun Feb 26 18:39:02 GMT-12:00 2006 =========== step 5 output end ================== 6. Select Windows XP timezone again as (GMT+10:00) Canberra, Melbourne, Sydney. 7. Check on the 'Automatically adjust clock for daylight saving changes'. 8. Change the timezone to (GMT-12:00) International Dateline West. 9. Run the test program again. It'll give you a similar output like below. It's incorrect. =========== step 9 output begin =============== timezone is sun.util.calendar.ZoneInfo[id="Pacific/Majuro",offset=43200000,dstSavings=0,useDaylight=false,transitions=4,lastRule=null] time is Mon Feb 27 18:37:53 MHT 2006 =========== step 9 output end ================== Notice that, Pacific/Majuro is a timezone of GMT+12. So the application gets 24-hours time difference as the DST is on and not for GMT-12 on Windows.
|