我昨天创造了这个奇妙的静态方法,和它的工作就好了 - 昨天解析ISO_INSTANT和类似的日期时间字符串
然而,今天,它给了我这个错误。我猜这是从Z前的太多0开始的。
任何人都可以推荐如何以简明的方式解析这种类型的String
格式日期 - 请记住它昨天也有效,所以ISO_INSTANT
也是String
的有效格式?
Caused by: java.time.DateTimeException: Unable to obtain LocalDate from TemporalAccessor: {NanoOfSecond=0, InstantSeconds=1443451604, MilliOfSecond=0, MicroOfSecond=0},ISO of type java.time.format.Parsed
at java.time.LocalDate.from(LocalDate.java:368)
at java.time.LocalDateTime.from(LocalDateTime.java:456)
... 9 more
投掷输入时间异常: “2015-09-28T14:46:44.000000Z”
/**
*
* @param time the time in RFC3339 format (e.g. "2013-07-03T14:30:38Z")
* @return
*/
public static LocalDateTime parseTimeINSTANT(String time) {
DateTimeFormatter f = DateTimeFormatter.ISO_INSTANT;
return LocalDateTime.from(f.parse(time));
}
ISO_INSTANT不支持时区,可以固定类似: 'Instant.from(DateTimeFormatter.ISO_DATE_TIME.parse(“2017-04-20T00:00: 00 + 04:00“))' –