JDK-6286592 : (fmt) Formatter "%tz" returns wrong GMT time offset during daylight savings time
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-06-16
  • Updated: 2017-05-16
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 Other
7 b20Fixed OpenJDK6Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

EXTRA RELEVANT SYSTEM CONFIGURATION :
default locale: de_AT
time zone: central european time (Berlin, Vienna), daylight saving.

A DESCRIPTION OF THE PROBLEM :
%tz of java.util.Formatter shows a wrong GMT timezone offset.
See example code.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the attached source code.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the GMT timezone offset of "%tz" should be the GMT time zone offset -
like  "Z" of SimpleDateFormat.

SimpleDateFormat: 2005-06-08 12:56:22.177 +0200
format date+time: should be identical

ACTUAL -
SimpleDateFormat: 2005-06-08 12:56:22.177 +0200
format date+time: 2005-06-08 12:56:22.177 +0100
... %tz gives a wrong GMT time offset.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
    Date now = new Date ();
    System.out.println ("SimpleDateFormat: " +
      new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS Z").format (now));
    System.out.format ("format date+time: %tF %<tT.%<tL %<tz%n", now);

---------- END SOURCE ----------
###@###.### 2005-06-16 11:48:03 GMT

Comments
SUGGESTED FIX *************** *** 3858,3864 **** break; } case DateTime.ZONE_NUMERIC: { // 'z' ({-|+}####) - ls minus? ! int i = t.get(Calendar.ZONE_OFFSET); boolean neg = i < 0; sb.append(neg ? '-' : '+'); if (neg) --- 3861,3867 ---- break; } case DateTime.ZONE_NUMERIC: { // 'z' ({-|+}####) - ls minus? ! int i = t.get(Calendar.ZONE_OFFSET) + t.get(Calendar.DST_OFFSET); boolean neg = i < 0; sb.append(neg ? '-' : '+'); if (neg) *** (#1 of 1): [ UNSAVED ] ###@###.###
20-06-2007

EVALUATION Oops. It appears that the GMT offset computation incorrectly neglected to adjust for DST. The specification needs to be updated to indicate this behaviour. While we're looking at the specification for time zone conversions, I see that we've also neglected to mention where we get time zone data for long and java.util.Date. This should also be specified.
20-06-2007