JDK-4460765 : Timezone with 1/2 hour offset parsed incorrectly
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-05-18
  • Updated: 2001-05-24
  • Resolved: 2001-05-24
Related Reports
Duplicate :  
Description

Name: bsC130419			Date: 05/18/2001


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

Timezone with 1/2 hour offset parsed incorrectly, unless TZ prefixed by GMT :-

In the 'Test2' example below, the timezone of +9:30 is incorrectly parsed by
the SimpleDateFormat pattern as +9:00 (the 1/2 hour offset is dropped).
Only by specifying the zone as GMT+9:30 does the parser correctly interpret the
date.

 Test 1 : 2001/05/15T17:15:55.333 +9:00 Out 1 : 2001/05/15T04:15:55.333 Eastern
Daylight Time
 Test 2 : 2001/05/15T17:15:55.333 +9:30 Out 2 : 2001/05/15T04:15:55.333 Eastern
Daylight Time
 Test 3 : 2001/05/15T17:15:55.333 GMT+9:30 Out 3 : 2001/05/15T03:45:55.333
Eastern Daylight Time


import java.text.*;
import java.util.*;
class Test {
    public static void main(String args[]) {
        String test1 = "2001/05/15T17:15:55.333 +9:00";
        String test2 = "2001/05/15T17:15:55.333 +9:30";
        String test3 = "2001/05/15T17:15:55.333 GMT+9:30";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd'T'HH:mm:ss.SSS
zzzz");

        try {
            System.out.println(" Test 1 : "+test1+" Out 1 : "+(sdf.format
(sdf.parse(test1))));
            System.out.println(" Test 2 : "+test2+" Out 2 : "+(sdf.format
(sdf.parse(test2))));
            System.out.println(" Test 3 : "+test3+" Out 3 : "+(sdf.format
(sdf.parse(test3))));
        } catch(ParseException e) {
             System.out.println("ParseException ");
        }
    }
}
(Review ID: 124639) 
======================================================================

Comments
WORK AROUND Name: bsC130419 Date: 05/18/2001 Prefix all 1/2 hour timezone offsets with GMT. ======================================================================
11-06-2004

EVALUATION The correct syntax of time zone for SimpleDateFormat.parse() is GMT+hours:minutes and GMT-hours:minutes as documented in SimpleDateFormat. However, there is some spec vs. implementation issue. See 4212077. masayoshi.okutsu@Eng 2001-05-24
24-05-2001