-
Bug
-
Resolution: Unresolved
-
P4
-
6u26
-
x86
-
linux
FULL PRODUCT VERSION :
Java version: 1.6.0_26,Sun Microsystems Inc.
Java Runtime: Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java VM: Java HotSpot(TM) 64-Bit Server VM 20.1-b02,Sun Microsystems Inc.
ADDITIONAL OS VERSION INFORMATION :
# uname -a
Linux 2.6.37.6-0.7-desktop #1 SMP PREEMPT 2011-07-21 02:17:24 +0200 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/SuSE-release
openSUSE 11.4 (x86_64)
VERSION = 11.4
CODENAME = Celadon
A DESCRIPTION OF THE PROBLEM :
When using the DateFormat class to format dates for display, with a locale of no or nb, the date format returned is the US standard, not Norwegian.
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
This returns MM/dd/yyyy rather than dd.mm.yyyy
Testing indicates that using a locale of no_NO_B or no_NO_NY are correct, but browsers to not provide those codes as choices for users to select during normal operation.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Write a servlet that retrieves a user's locale via request.getLocale() and creates a date format with the following code:
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
and writes the current date to the http response with the above format object.
2. Deploy the servlet to a web container such as Tomcat or JBoss.
3. Set browser locale to no or nb (Norwegian, Norwegian Bokmal)
4. Access the servlet, observe the date display.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Date displayed in MM/dd/yyyy format
ACTUAL -
Date displayed in dd.MM.yyyy format
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Locale;
/**
* Print out some date formats for different Locales.
*
* @author Don Smith
* @since 20-Oct-2011
*/
public class DateFormatExample
{
private static final Locale[] LOCALES = {
Locale.US,
Locale.UK,
Locale.CANADA,
Locale.CANADA_FRENCH,
Locale.FRANCE,
new Locale("no"),
new Locale("nb"),
new Locale("no_NO"),
new Locale("no_NO_B"),
new Locale("no_NO_NY")
};
public static void main(String [] args)
{
Calendar currentDate = Calendar.getInstance();
for (Locale loc : LOCALES) {
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, loc);
String dateNow = formatter.format(currentDate.getTime());
System.out.println("Date format for Locale " + loc.getDisplayName() + ": " + dateNow);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Passing in an explicit format.
Java version: 1.6.0_26,Sun Microsystems Inc.
Java Runtime: Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java VM: Java HotSpot(TM) 64-Bit Server VM 20.1-b02,Sun Microsystems Inc.
ADDITIONAL OS VERSION INFORMATION :
# uname -a
Linux 2.6.37.6-0.7-desktop #1 SMP PREEMPT 2011-07-21 02:17:24 +0200 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/SuSE-release
openSUSE 11.4 (x86_64)
VERSION = 11.4
CODENAME = Celadon
A DESCRIPTION OF THE PROBLEM :
When using the DateFormat class to format dates for display, with a locale of no or nb, the date format returned is the US standard, not Norwegian.
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
This returns MM/dd/yyyy rather than dd.mm.yyyy
Testing indicates that using a locale of no_NO_B or no_NO_NY are correct, but browsers to not provide those codes as choices for users to select during normal operation.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Write a servlet that retrieves a user's locale via request.getLocale() and creates a date format with the following code:
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
and writes the current date to the http response with the above format object.
2. Deploy the servlet to a web container such as Tomcat or JBoss.
3. Set browser locale to no or nb (Norwegian, Norwegian Bokmal)
4. Access the servlet, observe the date display.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Date displayed in MM/dd/yyyy format
ACTUAL -
Date displayed in dd.MM.yyyy format
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Locale;
/**
* Print out some date formats for different Locales.
*
* @author Don Smith
* @since 20-Oct-2011
*/
public class DateFormatExample
{
private static final Locale[] LOCALES = {
Locale.US,
Locale.UK,
Locale.CANADA,
Locale.CANADA_FRENCH,
Locale.FRANCE,
new Locale("no"),
new Locale("nb"),
new Locale("no_NO"),
new Locale("no_NO_B"),
new Locale("no_NO_NY")
};
public static void main(String [] args)
{
Calendar currentDate = Calendar.getInstance();
for (Locale loc : LOCALES) {
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, loc);
String dateNow = formatter.format(currentDate.getTime());
System.out.println("Date format for Locale " + loc.getDisplayName() + ": " + dateNow);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Passing in an explicit format.