引用SimpleDateFormat 的 Javadoc:
对于格式,如果模式字母的数量为 4 个或更多,则使用完整的形式;否则,如果可用,则使用简短或缩写形式
因此: (a) 如果您希望看到差异,请使用aaaa
(4 x a
) 而不是aaa
(4 x a
)。(b) 鉴于 AM/PM 没有短格式(或长格式),那么对于说明a
符而言,重复次数无关紧要。
为了更彻底一点,我运行了以下程序。它发现格式受到影响的情况为零。
Date date = new Date();
int n = 0;
for (String country : Locale.getISOCountries()) {
for (String language : Locale.getISOLanguages()) {
Locale loc = new Locale(language, country);
String as = "";
String prev = null;
for (int i = 0; i < 20; ++i) {
++n;
as += "a";
String current = new SimpleDateFormat(as, loc).format(date);
if (prev != null && !prev.equals(current)) {
System.out.println("Locale: " + loc + ", as=" + as + ", current="
+ prev + ", next=" + current);
}
prev = current;
}
}
}
System.out.println("Tried out " + n + " combinations.");