JDK-4060495 : Time is Being Changed with Locale Change when using DateFromat
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.1.1,1.1.4
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic,solaris_2.6
  • CPU: generic,sparc
  • Submitted: 1997-06-20
  • Updated: 1997-10-23
  • Resolved: 1997-10-23
Related Reports
Duplicate :  
Relates :  
Description
This problem duplicated on both Windows NT 4.0 running JDK 1.1.2 and Solaris running JDK 1.1.1A.

To duplicat this problme run the following code.


import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

public class DateTest{
    
public DateTest(){}

public static void main(String args[]){
    Date testDate = new Date (97, 9-1, 15);
    DateFormat dfFrench = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM, Locale.FRENCH);
    DateFormat dfUS = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM, Locale.US);
    System.out.println("Date set to : " + testDate);
    System.out.println("Date Formated with French Locale " + dfFrench.format(testDate));
    System.out.println("Date Formated with US Locale " + dfUS.format(testDate));
}
} 


Output: 

Date set to : Mon Sep 15 00:00:00 PDT 1997
Date Formated with French Locale lundi, 15 septembre 1997 09:00:00
Date Formated with US Locale Monday, September 15, 1997 12:00:00 AM


When a static date is set shouldn't the same time be returned for both Locales?  For example if I was in France working with a US Locale setting I would get a complete different time. 

I have tried changing the TimeZone and Locale environment varibles in Windows NT 4.0 with a Japanese Locale and I was still experiencing the same problem problem.  In that case the same date is returned but the time is 8:00 AM for the same date that returned 12:00am with the Locale and Regional settings set to US. 


Comments
WORK AROUND getDefault() from class TimeZone. Then explicitly set the TimeZone of the Calendar of the DateFormat class to be the TimeZone one gets from the first step. ###@###.###
11-06-2004

SUGGESTED FIX In java/util/TimeZone.java, the defaultZone is set according to System.getProperty("user.timezone", "GMT") But in java/text/DateFormat.java, the default TimeZone is set according to locale. getDefault() in DateFormat.java should get TimeZone as in TimeZone.java. The default time zone should be the same as the system time zone not the locale time zone. (In Solaris, if one changes locale the time zone is still the system time zone. Thus, an American using C locale in Tokyo still sees Japan local time with Unix date command.) ###@###.###
11-06-2004