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

[Fmt-Da] java.text.SimpleDateFormat parse not correct

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P3 P3
    • None
    • 1.4.2
    • core-libs
    • x86
    • windows_2000

      FULL PRODUCT VERSION :
      eclipse 3.0

      C:\Dokumente und Einstellungen\werner>java -version
      java version "1.4.2_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
      Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 2000

      A DESCRIPTION OF THE PROBLEM :
       * ---- SimpleDateFormat ----
       *
       * I've parsed the same string under different formats.
       * Here are the results:
       *
       * 1. is very incompatible
       * --------------------------------------------------
       * Date-String to parse: 1999-12-05T09:08:07+0305
       * Format for parsing: yyyyMMdd
       * Result: 1998-11-02 00:00:00.000 +0100
       * ---------- but error should occur ----------------
       *
       * 2. an appended time zone does'nt detect
       * --------------------------------------------------
       * Date-String to parse: 1999-12-05T09:08:07+0305
       * Format for parsing: yyyy-MM-dd'T'HH:mm:ss
       * Result: 1999-12-05 09:08:07.000 +0100
       * ---------- but error should occur ----------------
       *



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * Erzeugt: 07.12.2004
       * Author: peter werner
       *
       * Security Engineering
       * Business Unit ITC Security
       * T-Systems-International
       * Goslarer Ufer 35, 10589 Berlin
       *
       * ###@###.###
       *
       * This Java program demontrates 2 errors in Class
       * ---- SimpleDateFormat ----
       *
       * I've parsed the same string under different formats.
       * Here are the results:
       *
       * 1. is very incompatible
       * --------------------------------------------------
       * Date-String to parse: 1999-12-05T09:08:07+0305
       * Format for parsing: yyyyMMdd
       * Result: 1998-11-02 00:00:00.000 +0100
       * ---------- but error should occur ----------------
       *
       * 2. an appended time zone does'nt detect
       * --------------------------------------------------
       * Date-String to parse: 1999-12-05T09:08:07+0305
       * Format for parsing: yyyy-MM-dd'T'HH:mm:ss
       * Result: 1999-12-05 09:08:07.000 +0100
       * ---------- but error should occur ----------------
       *
       */
      package test;

      import java.text.FieldPosition;
      import java.text.ParseException;
      import java.text.SimpleDateFormat;
      import java.util.Date;

      /**
       * @author werner
       *
       * TODO To change the template for this generated type comment go to
       * Window - Preferences - Java - Code Generation - Code and Comments
       */
      public class TestDateTime1 {
      String format = "yyyyMMdd"; //bug 1
      String date = "1999-12-05T09:08:07+0305"; //bug 1

      //switch comments to show bug 2
      //String format = "yyyy-MM-dd'T'HH:mm:ss"; //bug 2
      //String date = "1999-12-05T09:08:07+0305"; //bug 2


      public static void main(String[] args) {
      TestDateTime1 tdt = new TestDateTime1();
      tdt.xxx();
      }

      public void xxx() {
      try {
      SimpleDateFormat sdf = new SimpleDateFormat(format);
      Date d = sdf.parse(date);
      System.getProperty().
      System.out.println("--------------------------------------------------");
      System.out.println("Date-String to parse: "+date);
      System.out.println("Format for parsing: "+format);
      System.out.println("Result: "+toString(d)+"\n");
      System.out.println("---------- but error should occur ----------------");
      } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }
      }

      public String toString(Date d) {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z");
      StringBuffer sb = new StringBuffer("");
      sdf.format(d, sb, new FieldPosition(0));
      return sb.substring(0);
      }
      }

      ---------- END SOURCE ----------
      ###@###.### 2004-12-08 09:41:24 GMT

            peytoia Yuka Kamiya (Inactive)
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: