【发布时间】:2020-01-07 10:13:53
【问题描述】:
运行以下代码时,我会在不同版本的 JDK 中得到不同的行为:
在 Java 8 中我得到:
2020-01-07T09:34:38.994Z
在 Java 11 中我得到:
2020-01-07T09:37:05.55126Z
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
public class MyClass {
public static void main(String args[]) {
ZonedDateTime now = ZonedDateTime.now();
DateTimeFormatter isoOffsetDateTime = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
String format = isoOffsetDateTime.format(now);
System.out.println(format);
}
}
在https://www.jdoodle.com/online-java-compiler/ 中运行只是为了更轻松地快速交换 JDK
此更改是否记录在任何地方,因为我找不到任何内容和/或有人知道为什么会发生这种情况?我发现这是因为 DateTimeFormatter.ISO_OFFSET_DATE_TIME 是 ZonedDateTime 的默认 Jackson 格式化程序。
【问题讨论】:
-
这能回答你的问题吗? ZonedDateTime change behavior jdk 8/11
-
@amer 这似乎是一个不同的问题(与时区有关,而这与小数秒的精度有关)
-
@MarkRotteveel 好吧,我的错
标签: java