小编bds*_*dow的帖子

LocalDateTime.parse处的java.time.format.DateTimeParseException

为什么执行以下代码:

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class TestProject {

    public static void main(String[] args) {
        String dateString = "2018-03-01T14:52:48Z";
        DateTimeFormatter dtf = DateTimeFormatter.ISO_INSTANT;
        LocalDateTime localDateTime = LocalDateTime.parse(dateString, dtf);
    }
}
Run Code Online (Sandbox Code Playgroud)

扔:

Exception in thread "main" java.time.format.DateTimeParseException: Text '2018-03-01T14:52:48Z' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {NanoOfSecond=0, InstantSeconds=1519915968, MilliOfSecond=0, MicroOfSecond=0},ISO of type java.time.format.Parsed
    at java.base/java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1959)
    at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1894)
    at java.base/java.time.LocalDateTime.parse(LocalDateTime.java:492)
    at org.bdshadow.TestProject.main(TestProject.java:11)
Caused by: java.time.DateTimeException: Unable to obtain LocalDateTime from TemporalAccessor: {NanoOfSecond=0, InstantSeconds=1519915968, MilliOfSecond=0, MicroOfSecond=0},ISO of type java.time.format.Parsed
    at …
Run Code Online (Sandbox Code Playgroud)

java

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

标签 统计

java ×1