Java 直布罗陀日期格式:期望类似GB的格式,而我们希望类似GB的格式

Java 直布罗陀日期格式:期望类似GB的格式,而我们希望类似GB的格式,java,locale,date-formatting,Java,Locale,Date Formatting,与乔达: Locale=newlocale(“en”、“GI”);//直布罗陀 DateTimeFormatter formatter=DateTimeFormat.shortDate().withLocale(locale); DateTime日期=新的日期时间(2019、6、20、9、30);//2019年6月20日 字符串格式化=date.toString(格式化程序); 使用Java8: Locale=newlocale(“en”、“GI”);//直布罗陀 DateTimeFormat

与乔达:

Locale=newlocale(“en”、“GI”);//直布罗陀
DateTimeFormatter formatter=DateTimeFormat.shortDate().withLocale(locale);
DateTime日期=新的日期时间(2019、6、20、9、30);//2019年6月20日
字符串格式化=date.toString(格式化程序);
使用Java8:

Locale=newlocale(“en”、“GI”);//直布罗陀
DateTimeFormatter formatter=DateTimeFormatter.ofCalizedDate(FormatStyle.SHORT).withLocale(locale);
LocalDateTime日期=LocalDateTime.of(2019,6,20,9,30);//2019年6月20日
字符串格式=格式化程序。格式(日期);
在这两种情况下,
formatted
等于
6/20/19
,而我预期的
20/06/19
,因为维基百科声明了这一点

有没有关于修复的想法(不同于“if GI然后GB”)


注意:当您使用
新语言环境(“en”,“GB”)
时,您确实得到了预期的结果。

在Java 9中修复+@Andreas是正确的:虽然我可以在Java 8(1.8.0121)上重现您的结果,但在Java 9(9.0.4)上,我得到了您说想要的
20/06/2019
(用Java.time测试)。哦,好的,感谢您检查了Java 9,我应该在问之前做些什么。好吧,我会一直干下去,直到我们将代码库迁移到Java9+,谢谢!可怜的直布罗陀人…我投票结束这个问题,因为它在Java的更高版本中得到了修复。