Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Date format issue

Reply
Thread Tools

Date format issue

 
 
RameshOracle@gmail.com
Guest
Posts: n/a
 
      10-29-2007
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

 
Reply With Quote
 
 
 
 
petersprc
Guest
Posts: n/a
 
      10-29-2007
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.Local eElements",
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, (E-Mail Removed) wrote:
> 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



 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-29-2007
On Sun, 28 Oct 2007 23:38:35 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote,
quoted or indirectly quoted someone who said :

> 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?
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-29-2007
On Mon, 29 Oct 2007 11:07:34 -0000, petersprc <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>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.

--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Newbie UK Date problem] Ways atround this UK date format localisation/SQLselection issue? DC ASP .Net 5 07-01-2005 09:35 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Date Format - best way of converting a string into a date format Brian Candy ASP .Net 2 02-18-2004 02:13 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Given a date, how to find the beginning date and ending date of that week Matt C++ 2 11-08-2003 08:30 PM



Advertisments