Microsoft SDK for Java

Q233271 FIX: DateFormat Class Does Not Default to the System Time Zone

The information in this article applies to:

SYMPTOMS

When using the java.text.DateFormat class, you will observe that it properly sets the time/date. However it does not display the time corresponding to the default system time zone set on your machine. Instead, it defaults to the first time zone of the system's locale. (For US English, the default would always be PST/PDT.)

CAUSE

The problem is that the time zone is not set by default in the versions of the Microsoft VM prior to build 3181.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

This problem has been fixed in Microsoft VM builds 3181 or later. The latest build is available at:

http://www.microsoft.com/java/ This link takes you to a site on microsoft.com

If you are using a Microsoft VM build prior to this version, then the workaround is to call setTimeZone on the DateFormat object.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new Console Application project using Microsoft® Visual J++® 6.0.

  2. Include the following piece of code in its main method:
    Calendar now = Calendar.getInstance();
       DateFormat df = DateFormat.getDateTimeInstance();
       //df.setTimeZone(TimeZone.getDefault());-->Uncomment this to fix the problem
       System.out.println(df.format(now.getTime()));
  3. Build and execute the above code. This displays the correct date and time.

  4. Now open Control Panel, select Date/Time and change the Time Zone to Eastern Time Zone (EST) on your machine.

  5. Rerun the above code. It still displays the time as if the machine were set to Pacific Time Zone.

REFERENCES

For the latest Knowledge Base articles and other support information on Visual J++ and the Microsoft® SDK for Java, please see the following pages on the Microsoft Technical Support site:

http://support.microsoft.com/support/visualj/ This link takes you to a site on microsoft.com

http://support.microsoft.com/support/java/ This link takes you to a site on microsoft.com

© 1999 Microsoft Corporation. All rights reserved. Terms of use.