我正在尝试根据国家/地区打印日期格式模式。 像这儿: 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
问:如何按国家/地区获取日期格式模式?
答案 0 :(得分:1)
...阿
我应该指定语言:
Locale locale = new Locale("en", countryCode);
这是一种奇怪的行为......
啊..它的点或斜线也取决于语言。
如果我使用" de",那么我有点......嗯..