我想用DateTimeFormatter.ISO_LOCAL_DATE
來打印和解析日期。這是我在做什麼印刷:如何使用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)
這工作對我來說 – Jerry06
在這裏工作很好Java 1.8 – MadProgrammer
我的不好,更新了問題,它是打印,不解析 – yegor256