java - 直布罗陀日期格式:预期类似 GB 的格式,而得到类似美国的格式
问题描述
与乔达:
Locale locale = new Locale("en", "GI"); // Gibraltar
DateTimeFormatter formatter = DateTimeFormat.shortDate().withLocale(locale);
DateTime date = new DateTime(2019, 6, 20, 9, 30); // 20 June 2019
String formatted = date.toString(formatter);
使用 Java8:
Locale locale = new Locale("en", "GI"); // Gibraltar
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withLocale(locale);
LocalDateTime date = LocalDateTime.of(2019, 6, 20, 9, 30); // 20 June 2019
String formatted = formatter.format(date);
在这两种情况下,formatted
都等于6/20/19
当我期待20/06/19
时,因为维基百科指出直布罗陀日期格式是 dd/mm/yyyy。
任何修复的想法(不同于“如果 GI 然后 GB”)?
注意:当你使用 时new Locale("en", "GB")
,你会得到预期的结果。