Date format issue

Discussion in 'Java' started by RameshOracle@gmail.com, Oct 29, 2007.

  1. Guest

    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
     
    , Oct 29, 2007
    #1
    1. Advertising

  2. petersprc Guest

    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.

    On Oct 29, 1:38 am, 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
     
    petersprc, Oct 29, 2007
    #2
    1. Advertising

  3. Roedy Green Guest

    On Sun, 28 Oct 2007 23:38:35 -0700, 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
     
    Roedy Green, Oct 29, 2007
    #3
  4. Roedy Green Guest

    On Mon, 29 Oct 2007 11:07:34 -0000, petersprc <>
    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
     
    Roedy Green, Oct 29, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candy
    Replies:
    2
    Views:
    1,205
    Janaka
    Feb 18, 2004
  2. DC
    Replies:
    5
    Views:
    3,035
    Brendan Reynolds
    Jul 1, 2005
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,370
    Michael Borgwardt
    May 30, 2004
  4. Chu
    Replies:
    3
    Views:
    4,233
    Shawn
    Aug 15, 2006
  5. Josh Sharpe
    Replies:
    1
    Views:
    227
    Brian Candler
    Sep 21, 2010
Loading...

Share This Page