Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4460765

Timezone with 1/2 hour offset parsed incorrectly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • core-libs
    • x86
    • windows_2000



      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)
      ======================================================================

            okutsu Masayoshi Okutsu
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: