Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
Name: vi73552 Date: 03/30/99 This may be demonstrated by the following code: ///////////////////////// File T.java ///////////////////////////////// import java.util.*; public class T { public static void main(String[] args) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(new Date()); int hr = cal.get(Calendar.HOUR_OF_DAY); int tzo = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET); tzo /= 3600000; // Convert to hours. System.out.println("tzo = "+tzo+", hr = "+hr); } } //////////////////////// End of File /////////////////////////////////// I have run this program with my computer's clock set to various different timezones and dates, and everything works well, eg for Russian Standard Time (in winter, with no daylight saving) the program gives the output: tzo = 3, hr = <<same as system clock>> while in summer, ie Russian Daylight Time, the output is: tzo = 4, hr = <<same as system clock>> Also, for Greenwich Mean Time (Britain in winter), the output is as expected: tzo = 0, hr = <<same as system clock>> The problem arises when I set the system clock to British Summer Time by selecting 'Greenwich Mean Time' for the time zone and setting the calendar to a summer month. Then the output of the program is: tzo = 0, hr = <<one hour less than the system clock>> instead of the correct 'tzo = 1, hr = <<same as system clock>>'. In other words, the hour is the GMT hour, and the offset is the GMT offset, but this contradicts the system clock which is showing British Summer Time. (There seems to be a jinx on British Summer Time: in Java 1.0 the timezone offset returned by java.util.Date for BST was 59 minutes instead of 60 minutes!) I hope this is helpful. Please contact me if you want any further info. Tom Nicholson. Tel. 44 (0)181 473 9144 (UK) ###@###.### java version 1.2 full version JDK-1.2-V (Review ID: 56302) ====================================================================== Name: krT82822 Date: 04/08/99 All Windows NT SP 4.0; In JDK 1.1.8 RC && 1.2 && 1.1.7B the TimeZone is still unaware of British Summer Time. This is just unacceptable, this problem has been known about for a year and still isn't fixed even in 1.2! A year old known bug, that will effect everyone in the UK, managed to get through 'quality control'. It is hardly a difficult thing to test, whats the excuse ? Code to reproduce the problem follows, to make it work uncomment the static initialiser. import java.text.DateFormat; import java.util.Calendar; import java.util.TimeZone; import java.util.SimpleTimeZone; public class DateBug2 { /* static { System.out.println("TimeZone = " + TimeZone.getDefault().getID()); if (TimeZone.getDefault().getID().equals("GMT")) { SimpleTimeZone stz = new SimpleTimeZone(0, "DCH"); stz.setStartRule(Calendar.MARCH,-1,Calendar.SUNDAY,2*60*60*1000); stz.setEndRule(Calendar.OCTOBER,-1,Calendar.SUNDAY,2*60*60*1000); TimeZone.setDefault(stz); } System.out.println("TimeZone = " + TimeZone.getDefault().getID()); }*/ static DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM); static Calendar cal = Calendar.getInstance(TimeZone.getDefault()); public static void main(String[] args) throws Exception { System.out.println("(Main)TimeZone = " + TimeZone.getDefault().getID()); long currentTimeMillis; long calMillis; if (args.length > 0) { currentTimeMillis = Long.parseLong(args[0]); calMillis = Long.parseLong(args[0]); } else { currentTimeMillis = System.currentTimeMillis(); calMillis = Calendar.getInstance(TimeZone.getDefault()).getTime().getTime(); } System.out.println("currentTimeMillis " + currentTimeMillis ); System.out.println("calMillis " + calMillis ); System.out.println("util.Date " + new java.util.Date(currentTimeMillis ) ); System.out.println("currentTimeMillis " + df.format(new java.util.Date(currentTimeMillis ))); System.out.println("calMillis " + df.format(new java.util.Date(currentTimeMillis ))); System.out.println("in Daylight Savings ? " + TimeZone.getDefault().inDaylightTime(new java.util.Date(currentTimeMillis ))); } } ====================================================================== Name: krT82822 Date: 08/09/99 When obtaining the current date/time using Calendar in UK during daylight saving (British Summer Time - BST) using Windows NT Service Pack 4 or 5 the time is returned in GMT. Service Pack 3 provides the date/time correctly as BST (GMT + 1). A tame windows programmer has informed me after writing a test program in C++ that some of Microsoft's date handling stuff has changed between Service Pack 3 and Service Pack 4/5. (Review ID: 93682) ======================================================================
|