Couldn't translate Date to spanish with Locale("es_ES")

Go To


I'm trying to do a simple date format, it does work great, it's very easy, but the problem is the language. I used the locale "es_ES" to get "Miércoles" instead of "Wednesday" and sorts like that but i failed.

Here's my code:

SimpleDateFormat formato = 
    new SimpleDateFormat("EEEE d 'de' MMMM 'de' yyyy", new Locale("es_ES"));
String fecha = formato.format(new Date());

The EXPECTED value of the fecha string is:

Miércoles 4 de Abril de 2012

but i'm still getting:

Wednesday 4 de April de 2012

What am I doing wrong?

2012-04-04 20:51
by Ulises Layera
is the spanish locale available in Locale.getAvailableLocales()ratchet freak 2012-04-04 20:56
a good tip to get in mind, thank - Ulises Layera 2012-04-04 21:00


"es_ES" is a language + country. You must specify each part separately.

The constructors for Locale are:

You want new Locale("es", "ES"); to get the Locale that goes with es_ES.

However, it would be better to use Locale.forLanguageTag("es-ES"), using the well-formed IETF BCP 47 language tag es-ES (with - instead of _), since that method can return a cached Locale, instead of always creating a new one.

2012-04-04 20:56
by Affe
worked great, thank you very much, i must have looked the constructor - Ulises Layera 2012-04-04 21:01
What exactly is the variant for - Jose Serodio 2016-11-29 00:32
@JoseSerodio There are only 5 locales using variant: en_US_POSIX: English (United States,Computer), no_NO_NY: Norwegian (Norway,Nynorsk), th_TH_TH_#u-nu-thai: Thai (Thailand,TH), ja_JP_JP_#u-ca-japanese: Japanese (Japan,JP), ca_ES_VALENCIA: Catalan (Spain,Valencian)Andreas 2018-06-17 20:03


Java 8

LocalDate today =;
String day = today.getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("es","ES")));

Also works for month.

2016-08-24 22:27
by imTachu



String output = ( ZoneId.of ( "Europe/Madrid" ) )
    .format ( 
        DateTimeFormatter.ofLocalizedDate ( FormatStyle.FULL )
                         .withLocale ( new Locale ( "es" , "ES" ) ) 

martes 12 de julio de 2016


The accepted Answer by Affe is correct. You were incorrectly constructing a Locale object.


The Question and Answer both use old outmoded classes now supplanted by the java.time framework built into Java 8 and later. These classes supplant the old troublesome date-time classes such as java.util.Date. See Oracle Tutorial. Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport and further adapted to Android in ThreeTenABP.

These classes include the DateTimeFormatter to control the format of text when generating a String from your date-time value. You can specify an explicit formatting pattern. But why bother? Let the class automatically localize the format to the human language and cultural norms of a specific Locale.

For example, get the current moment in Madrid regional time zone.

ZoneId zoneId = ZoneId.of( "Europe/Madrid" );
ZonedDateTime zdt = zoneId );
// example: 2016-07-12T01:43:09.231+02:00[Europe/Madrid] 

Instantiate a formatter to generate a String to represent that date-time value. Specify the length of the text via FormatStyle (full, long, medium, short).

DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate ( FormatStyle.FULL );

Apply a Locale to substitute for the JVM’s current default Locale assigned to the formatter.

Locale locale = new Locale ( "es" , "ES" );
formatter = formatter.withLocale ( locale );

Use the formatter to generate a String object.

String output = zdt.format ( formatter );
// example: martes 12 de julio de 2016

Dump to console.

System.out.println ( "zdt: " + zdt + " with locale: " + locale + " | output: " + output );

zdt: 2016-07-12T01:43:09.231+02:00[Europe/Madrid] with locale: es_ES | output: martes 12 de julio de 2016

2016-07-11 23:30
by Basil Bourque


    Locale esLocale = new Locale("es", "ES");//para trabajar en español
    SimpleDateFormat formatter = new SimpleDateFormat(strFormatoEntrada, esLocale);//El formato con que llega mi strFecha más el lenguaje
2016-08-17 03:03
by Cristianetoo Geova