无法使用区域设置将日期翻译为西班牙语(“es_ES”) [英] Couldn't translate Date to spanish with Locale("es_ES")
本文介绍了无法使用区域设置将日期翻译为西班牙语(“es_ES”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做一个简单的日期格式,它的工作很好,很简单,但问题是语言。我使用了es_ES来获取Miércoles而不是星期三,并排序,但是我失败了。
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.
这是我的代码:
SimpleDateFormat formato =
new SimpleDateFormat("EEEE d 'de' MMMM 'de' yyyy", new Locale("es_ES"));
String fecha = formato.format(new Date());
fecha
字符串的EXPECTED值为:
The EXPECTED value of the fecha
string is:
2012年度欧洲美术馆
Miércoles 4 de Abril de 2012
但我仍然得到:
2012年4月4日(星期四)
Wednesday 4 de April de 2012
我做错了什么?
推荐答案
es_ES是一个语言+国家。您必须分别指定每个部分。
"es_ES" is a language + country. You must specify each part separately.
Locale
是:
- < a href =http://docs.oracle.com/javase/8/docs/api/java/util/Locale.html#Locale-java.lang.String-> Locale(String language)
从语言代码构建语言环境。 - Locale(String language,String country)
从语言,国家/地区构建语言环境。 - Locale(String language,String country,String variant)
从语言,国家/地区,变体构造语言环境。
- 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.
您需要新的区域设置(es,ES);
以获取与es_ES一起使用的区域设置。
You want new Locale("es", "ES");
to get the Locale that goes with es_ES.
这篇关于无法使用区域设置将日期翻译为西班牙语(“es_ES”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文