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

Timezone notation inconsistent

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1
    • core-libs
    • None
    • sparc
    • solaris_2.5.1



      Name: mc57594 Date: 02/28/97


      The class TimeZone handles time zone ids such as:
        EST, CST, MST, PST, AST, HST
      in the getTimeZone() method.

      But the SimpleDateFormat class parse() method only recognizes
      a subset of those time zone ids.

      For example:
        8 DEC 1996 7:00:00 PST
      can be parsed, but
        8 DEC 1996 7:00:00 AST
      results in NullPointerException in parse().


      In addition, the GMT notation is NOT supported by
      TimeZone.getTimeZone(String).

      For example:
        TimeZone.getTimeZone("AST")
      will work just fine, but
        TimeZone.getTimeZone("GMT-9:00")
      simply returns a null object.


      Bottom line
      -----------
      TimeZone.getTimeZone(String) and SimpleDateFormat("zzz")
      should recognize and handle the same time zone notations.


      Here is code to demonstrate these two points:

      import java.util.*;
      import java.text.*;

      class bug {

              public static void processTime(String timeString, String tzString) {

                      TimeZone tz = TimeZone.getTimeZone(tzString);
                      if (tz == null)
                      {
                              System.out.println("** Timezone " + tzString + " not recognized **");
                              return;
                      }

                      try {
                              SimpleDateFormat formatter = new SimpleDateFormat("d MMM
       yyyy h:mm:ss zzz");
                              Date val = formatter.parse(timeString);
                              formatter.setTimeZone(tz);
                              System.out.println("Date: " + formatter.format(val));
                      }
                      catch (Exception e) {
                              e.printStackTrace();
                      }
              }

              public static void main(String[] args) {

                      System.out.println("This works...");
                      processTime("8 DEC 1996 7:00:00 PST", "PST");
                      System.out.println();
                      System.out.println("This fails...");
                      processTime("8 DEC 1996 7:00:00 AST", "AST");
                      System.out.println();
                      System.out.println("This also fails...");
                      processTime("8 DEC 1996 7:00:00 GMT-9:00", "GMT-9:00");
              }
      }
      company - LSC Inc , email - ###@###.###
      ======================================================================

            ssenthilsunw Shanmugam Senthil (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: