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

SimpleDateFormat.parse() exception with GMT time zone

XMLWordPrintable

    • 1.1.8
    • x86
    • windows_95, windows_nt
    • Verified



        Name: tb29552 Date: 04/30/98


        Recent changes designed to fix the behavior of unnamed time zones such as
        "GMT+00:30" have introduced a bad side-effect: SimpleDateFormat.subParse()
        now throws an exception if you pass just "GMT" as the time zone (the +/-HH:MM
        is required). Code to reproduce the problem:

        /******** BEGIN TEST CODE ********/
        import java.text.ParsePosition;
        import java.text.SimpleDateFormat;
        import java.util.Date;

        public class Crash {
          public final static String dateFormat = "MM/dd/yy HH:mm:ss zzz";
          public static Date parse(String datestr)
          {
            SimpleDateFormat fmt = new SimpleDateFormat(dateFormat);
            ParsePosition p0 = new ParsePosition(0);
            return fmt.parse(datestr, p0);
          }
          static public void main(String[] args)
          {
            Date d = parse("01/22/92 04:52:00 GMT");
            System.out.println(d.toString());
          }
        };
        /******** END TEST CODE ********/

        At the very least, this isn't backward compatible with 1.1.5 and earlier, which
        parsed a plain GMT just fine. At worst, it's counter-intuitive (this should work).
         A plain GMT is a very common case.

        After looking at the bug database, it appears that this may have been
        fixed under 4106807 on 1998-03-10 as part of 1.2beta4, but sadly,
        the fix didn't make it into JDK 1.1.6.
        (Review ID: 29049)
        ======================================================================

              aliusunw Alan Liu (Inactive)
              tbell Tim Bell
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: