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

前端 未结 5 842
别跟我提以往
别跟我提以往 2020-12-05 23:06

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 \"W

5条回答
  •  天涯浪人
    2020-12-05 23:11

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

    The constructors for Locale are:

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

    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.

提交回复
热议问题