JDK-4035490 : Timezone notation inconsistent
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.1
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5.1
  • CPU: sparc
  • Submitted: 1997-02-28
  • Updated: 1997-10-23
  • Resolved: 1997-10-23
Related Reports
Duplicate :  
Description

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 - ###@###.###
======================================================================

Comments
WORK AROUND Name: mc57594 Date: 02/28/97 One must convert AST, HST time zones to GMT equilavents before calling parse() method. This is not very practical, since the whole purpose of parse() is to parse this information. And if you desire to use TimeZone.getTimeZone(String), you'll have to keep track of the non-GMT notation. ======================================================================
11-06-2004