1
我試圖根據國家打印日期格式模式。 喜歡這裏: https://en.wikipedia.org/wiki/Date_format_by_country獲取日期格式patterrn按國家
我嘗試:
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
問:如何通過國家獲取日期格式模式?