我正在尝试根据国家/地区打印日期格式模式。像这里:https://en.wikipedia.org/wiki/Date_format_by_country
我的尝试:
public class DateFormatTest {
public static void main(String[] args) {
String[] locales = Locale.getISOCountries();
for (String countryCode : locales) {
Locale locale = new Locale("", countryCode);
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
SimpleDateFormat simple = (SimpleDateFormat) dateFormat;
String pattern = simple.toPattern().replaceAll("\byy\b", "yyyy");
System.out.println(
"{" +
"id : '" + locale.getCountry() + "', " +
"format : '" + pattern + "'" +
"},");
}
}
}
但我得到了:所有国家'M/d/yyyy'
。
例如,对于德国,我期待这样的东西:dd.MMM.yyyy
英国:MMM/dd/yyyy
问:如何按国家/地区获取日期格式模式?
啊...
我应该指定语言:
Locale locale = new Locale("en", countryCode);
这是一种奇怪的行为...
啊......它在哪里点或斜线也取决于语言。
如果我使用"de",那么我有点.. 嗯。