Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Date format issue

Thread view: 
RameshOracle@gmail.com - 29 Oct 2007 07:38 GMT
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
petersprc - 29 Oct 2007 12:07 GMT
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[i]));
     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.

On Oct 29, 1:38 am, RameshOra...@gmail.com wrote:
> Hi All,
>             I need to print a date in Norwegian format. I am using
[quoted text clipped - 18 lines]
> Regards
> Ramesh
Roedy Green - 29 Oct 2007 13:51 GMT
>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.

Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Roedy Green - 29 Oct 2007 13:49 GMT
> 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?
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.