小编Ven*_*kat的帖子

Java8- ZonedDateTime,DateTimeFormatter无法识别格式

我正在使用ZonedDateTime和Java 8的DateTimeFormatter.当我尝试解析自己的模式时,它无法识别并抛出异常.

    String oraceDt = "1970-01-01 00:00:00.0";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S");
    ZonedDateTime dt = ZonedDateTime.parse(oraceDt, formatter);

Exception in thread "main" java.time.format.DateTimeParseException: Text '1970-01-01 00:00:00.0' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: {},ISO resolved to 1970-01-01T00:00 of type java.time.format.Parsed
at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1918)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1853)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
at com.timezone.Java8DsteTimes.testZonedDateTime(Java8DsteTimes.java:31)
at com.timezone.Java8DsteTimes.main(Java8DsteTimes.java:11)
Run Code Online (Sandbox Code Playgroud)

引起:java.time.DateTimeException:无法从TemporalAccessor获取ZonedDateTime:{},ISO解析为1970-01-01T00:00,类型为java.time.format.Parsed

java-8 java-time zoneddatetime

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

java-8 ×1

java-time ×1

zoneddatetime ×1