【发布时间】:2017-10-18 08:04:22
【问题描述】:
我想使用DateTimeFormatter.ISO_LOCAL_DATE 来打印和解析日期。这就是我正在做的打印:
Date date;
String text = DateTimeFormatter.ISO_LOCAL_DATE.format(
date.toInstant()
);
这就是我得到的:
java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: Year
at java.time.Instant.getLong(Instant.java:603)
at java.time.format.DateTimePrintContext$1.getLong(DateTimePrintContext.java:205)
at java.time.format.DateTimePrintContext.getValue(DateTimePrintContext.java:298)
at java.time.format.DateTimeFormatterBuilder$NumberPrinterParser.format(DateTimeFormatterBuilder.java:2543)
at java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2182)
at java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1744)
at java.time.format.DateTimeFormatter.format(DateTimeFormatter.java:1718)
【问题讨论】:
-
这对我有用
-
在 Java 1.8 中工作正常
-
我的错,更新了问题,它正在打印,而不是解析
标签: java date java-8 date-formatting java-time