JDK-4050886 : Date.toString() returns GMT timezones for TZ outside US (change from JDK1.0.2)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 1.1.1
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_9
  • CPU: sparc
  • Submitted: 1997-05-09
  • Updated: 1997-10-23
  • Resolved: 1997-10-23
Related Reports
Duplicate :  
Description
	java.util.Date.toString() returns GMT style timezones when
	outside US timezones in JDK1.1  This is different from JDK1.0.2

	For example when in BST (British Standard Time? in UK),
	Date.toString() in JDK1.1.1 returns something like:

	     Sat May 10 03:58:56 GMT+06:00 1997

	In JDK1.0.2 this same method returns a date string like:

    	     Fri May 09 21:59:36 BST 1997

	Note the "BST" vs. "GMT+06:00".  I got these strings by
	running the small test program below.  To switch to the
	BST timezone set the env var TZ=BST.  

import java.util.Date;
 
public class date {
    public static void main(String argv[]) {
        Date d = new Date();
        System.out.println("java date: " + d.toString());
    }
}

	Looking at the implementation of Date.toString in JDK1.1.1
	shows that it explicitly uses the US locale.  The problem may
	be that the DateFormatTimeZone_en.java resource bundle should
	include other non-us timezone names.  Or it may be that using
	the US locale is incorrect.  Or this may be intended.  It certainly
	causes confusion to the submitter of this bug.

--- Original description below ---

I have been running the applet (which I attach to this bug report) for some
time now on my home page (http://kelvin.uk/~petert). Under Netscape from
/usr/dist and earlier versions of hotjava it has worked fine. However, currently
the date printed out reads as follows:-

Fri May 09 13:51:59 GMT+01:00 1997

This is obviously wrong, under Netscape I get:-

Fri May 09 13:51:59 BST 1997

Which is correct.


Comments
EVALUATION robert.obrien@Eng 1997-05-09 The problem appears to be in the java.util.Date.toString() and not in HotJava. I've updated the description/synopsis to reflect this and included a simple test case. Sending to java/classes_util for further evaluation by JavaSoft.
11-06-2004

WORK AROUND Use another browser. robert.obrien@Eng 1997-05-09 Another workaround is to extend java.util.Date to do the toString() without the hardwired US locale as follows. This uses JDK1.1 API's so it wont work in Netscape until it supports JDK1.1. public class MyDate extends java.util.Date { public String toString() { DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); formatter.setTimeZone(TimeZone.getDefault()); return formatter.format(this); } }
11-06-2004