DateTimeFormatter.RFC_1123_DATE_TIME
你的日期时间字符串在
RFC 822
/
RFC 1123
DateTimeFormatter.RFC_1123_DATE_TIME
:
Instant result = DateTimeFormatter.RFC_1123_DATE_TIME
.parse("Sat, 29 Sep 2018 20:49:02 GMT", Instant::from);
System.out.println("Result: " + result);
结果:2018-09-29T20:49:02Z
按照RFC规范的要求,这个RFC1123格式化程序始终是英文的。我甚至试着把我的默认语言环境设置为
Locale.CANADA_FRENCH
,代码仍然有效。
你的代码哪里出错了?
Locale.CANADA
:
Sat.
Sep.
而不是
Sat
和
Sep
. 在Java10中,它们应该没有点,所以这里的解析是有效的。区别可能在于CLDR数据的不同版本,在上述任何Java版本中都很难被视为bug。由于Java9CLDR是Java中的默认语言环境数据,包括不同语言环境中的日和月缩写。
演示:使用格式化程序,但将其修改为
DateTimeFormatter dateFormatter = new DateTimeFormatterBuilder().
appendPattern("EEE, dd MMM yyyy HH:mm:ss zzz").
toFormatter(Locale.CANADA);
System.out.println("Sample: " + ZonedDateTime.now(ZoneId.of("America/Toronto"))
.format(dateFormatter));
在Java 10.0.2上运行时,这不会打印任何点:
样本:太阳,2018年9月30日美国东部时间10:39:28
在Java 11 build 11+28上:
所以我相信这种行为与你链接的bug报告无关。
链接