1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public class FormatStyleTest { public static void main(String[] args) { LocalDate ld = LocalDate.now(); Arrays.asList(FormatStyle.FULL, FormatStyle.LONG, FormatStyle.MEDIUM, FormatStyle.SHORT) .forEach(formatStyle -> { System.out.println(String.format("--- FormatStyle.%s ---", formatStyle.toString())); DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate(formatStyle); Arrays.asList(new String[]{"zh", "CN"}, new String[]{"zh", "HK"}, new String[]{"zh", "TW"}, new String[]{"en", "US"}, new String[]{"en", "UK"}, new String[]{"ja", "JP"}) .forEach(strs -> { Locale locale = new Locale(strs[0], strs[1]); System.out.println(String.format("%s %s -> %s", strs[0], strs[1], ld.format(dtf.withLocale(locale)))); }); });
} }
|