Problema de DateFormat con configuraciones regionales de país

I'm writing a multilingual Program and I have set my Locales to Country specific ones (e.g. de_AT, de_DE,en_US,en_GB). So if I call DateFormat.getDateInstance(int fomat,Locale l) I get always the English one! It works if I use language only Locales (e.g. En, de,...)

He revisado el Oracle Doc of DateFormat, but also with their examples the Error occurs.

Here is an example Program:

import java.text.DateFormat;
import java.util.Locale;
import java.util.Date;

public class DateFormatTest {
  public static void main(String args[]){
    Locale[] locales={new Locale("de_AT"),new Locale("de_DE"), new Locale("de"), new Locale("en_US"), new Locale("en"), new Locale("fr_FR"), new Locale("fr_CA"), new Locale("fr")};
    Date today= new Date();
    for(Locale l: locales){

Esta es la salida:

huwa@hubefl-ws:~/tmp$ javac 
huwa@hubefl-ws:~/tmp$ java DateFormatTest 
de_at   Nov 8, 2011 Tuesday, November 8, 2011
de_de   Nov 8, 2011 Tuesday, November 8, 2011
de      08.11.2011  Dienstag, 8. November 2011
en_us   Nov 8, 2011 Tuesday, November 8, 2011
en      Nov 8, 2011 Tuesday, November 8, 2011
fr_fr   Nov 8, 2011 Tuesday, November 8, 2011
fr_ca   Nov 8, 2011 Tuesday, November 8, 2011
fr      8 nov. 2011 mardi 8 novembre 2011

Has anybody the same problem? Is there a solution?

preguntado el 08 de noviembre de 11 a las 12:11

for your information, I have tried it on linux (ubuntu 10.04) useing java: java version "1.6.0_27" Java(TM) SE Runtime Environment (build 1.6.0_27-b07) Java HotSpot(TM) 64-Bit Server VM (build 20.2-b06, mixed mode) -

3 Respuestas

Según la javadocs, the constructors are

Locale(String language)
Locale(String language, String country)
Locale(String language, String country, String variant)

so when you are creating new Locale("de_AT"), it tries to use language "de_AT" which does not exist, so it falls back to the default (English).


Locale[] locales={new Locale("de", "AT"), new Locale("de", "DE"), ...};

respondido 08 nov., 11:16

The problem is the way you're constructing the Locale objects. Pass the country and language as separate arguments, e.g.

Locale[] locales = { new Locale("de", "AT"), new Locale("de", "DE"), 
    new Locale("de"), new Locale("en", "US"), new Locale("en"), 
    new Locale("fr", "FR"), new Locale("fr", "CA"), new Locale("fr")};

respondido 08 nov., 11:16



Respondido 12 Oct 13, 14:10

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.