Вопрос по date, java – Не удалось перевести дату на испанский с локалью («es_ES»)

28

Я пытаюсь создать простой формат даты, он отлично работает, это очень легко, но проблема в языке. Я использовал локаль & quot; es_ES & quot; чтобы получить "Mi & # xE9; rcoles" вместо "среда" и вроде как, но я не смог.

Вот мой код:

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

ОЖИДАЕМЫЕ значенияfecha Строка:

Miércoles 4 de Abril de 2012

но я все еще получаю:

Wednesday 4 de April de 2012

Что я делаю неправильно?

Error: User Rate Limit Exceeded Ulises Layera
Error: User Rate Limit ExceededLocale.getAvailableLocales() ratchet freak

Ваш Ответ

4   ответа
1
    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
4
Java 8
LocalDate today = LocalDate.now();
String day = today.getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("es","ES")));

3
tl;dr
String output = 
    ZonedDateTime.now ( ZoneId.of ( "Europe/Madrid" ) )
    .format ( 
        DateTimeFormatter.ofLocalizedDate ( FormatStyle.FULL )
                         .withLocale ( new Locale ( "es" , "ES" ) ) 
    )
;

Details

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit ExceededLocaleError: User Rate Limit Exceeded

java.time

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceededjava.util.DateError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded.

Error: User Rate Limit ExceededDateTimeFormatterError: User Rate Limit ExceededcanError: User Rate Limit ExceededLocale.

Error: User Rate Limit ExceededError: User Rate Limit Exceeded.

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

Error: User Rate Limit ExceededFormatStyleError: User Rate Limit Exceeded

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

Error: User Rate Limit ExceededLocaleError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded LocaleError: User Rate Limit Exceeded

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

Error: User Rate Limit Exceeded

String output = zdt.format ( formatter );
// example: 

Error: User Rate Limit Exceeded

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:

59

Locale

Locale(String language)
Construct a locale from a language code. Locale(String language, String country)
Construct a locale from language, country. Locale(String language, String country, String variant)
Construct a locale from language, country, variant.

new Locale("es", "ES");

Locale.forLanguageTag("es-ES")es-ES-_Locale

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded Ulises Layera
Error: User Rate Limit Exceededen_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)

Похожие вопросы