我格式化 ZonedDateTime 然后尝试解析它并得到以下异常。
public static void main(String[] args){
String timeStr=ZonedDateTime.now().format(DateTimeFormatter.ISO_INSTANT);
System.out.println(timeStr);
ZonedDateTime.parse(timeStr,DateTimeFormatter.ISO_INSTANT);
}
产生的异常
Exception in thread "main" java.time.format.DateTimeParseException: Text '2016-10-05T21:38:26.191Z' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: {MicroOfSecond=191000, MilliOfSecond=191, InstantSeconds=1475703506, NanoOfSecond=191000000},ISO of type java.time.format.Parsed
at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1920)
我需要能够在该字符串格式之间转换时间。最好的方法是什么?