Date format issue

R

RameshOracle

Hi All,
I need to print a date in Norwegian format. I am using
DateFormat.format() method to print the date. But it prints something
like "29. november 2007". One can notice that its not showing the Day
name like (Monday).
Do you have any ideas.. It seems to work for other locales correctly.
I have tried with JDK1.4/1.5 too.

Below is the code snippet:

loc = new Locale("de","DEU");
Locale.setDefault(loc);
Calendar cal = Calendar.getInstance();
cal.set(2007, 10, 29);
DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, l);
System.out.println("Default locale "+Locale.getDefault());
System.out.println("Date formatted "+df.format(cal.getTime()));

It displays: 29. november 2007

Regards
Ramesh
 
P

petersprc

Seems to be a slight incompatibility between the CLDR and the jre for
Norwegian. The date pattern should be "EEEE d. MMMM yyyy".

You can use com.ibm.icu.text.DateFormat instead of
java.text.DateFormat which shows the correct format.

You could also make an exception in this case and use SimpleDateFormat
with a pattern of "EEEE d. MMMM yyyy" when Norwegian is the language.

You may also be able to hack the locale's date strings to use the
correct pattern. I don't think this is recommended:

public static void fixNorwegianDateFormat()
{
String[] variants = {"NO", "NO_NY"};
for (int i = 0; i < variants.length; i++) {
ResourceBundle rb =
ResourceBundle.getBundle("sun.text.resources.LocaleElements",
new Locale("no", variants));
String[] pats = rb.getStringArray("DateTimePatterns");
pats[DateFormat.FULL + 4] = "EEEE d. MMMM yyyy";
pats[DateFormat.LONG + 4] = "EEEE d. MMMM yyyy";
}
}

Finally, you might be able to create a custom resource class called
sun.text.resources.LocalElements_no_NO_X that overrides the
DateTimePatterns element and then use that locale "no_NO_X" instead of
"no_NO". But I don't believe such a hack is recommended either.

In any case, I would use com.ibm.icu.text.DateFormat from icu4j if you
can.
 
R

Roedy Green

I need to print a date in Norwegian format.

1. what is Norwegian format supposed to look like in your opinion?
Here in Canada you find 4 formats touted as "Canadian".
yyyy.mm.dd yyyy/mm/dd dd/mm/yyyy mm/dd/yyyy
I figure it is time to drop local formats and go with the unambiguous
ISO 2007-12-31.

2. why are you using a German locale to get a Norwegian format?
Does Sun not support Norwegian directly?
 
R

Roedy Green

Seems to be a slight incompatibility between the CLDR and the jre for
Norwegian. The date pattern should be "EEEE d. MMMM yyyy".

You can use com.ibm.icu.text.DateFormat instead of
java.text.DateFormat which shows the correct form

see http://mindprod.com/jgloss/bug.html

If you can prove from some official source the expected format, rather
than just personal opinion, you can report it to Sun as a bug to be
fixed. It is easy to fix, so they will likely give it high priority.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top