【发布时间】:2016-07-23 13:03:01
【问题描述】:
将字符串解析为本地日期时间时遇到一个奇怪的问题
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Main {
public static void main(String args[])
{
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_TIME;
LocalDateTime.parse("00:00",formatter);
}
}
给我:
Exception in thread "main" java.time.format.DateTimeParseException: Text '00:00' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 00:00 of type java.time.format.Parsed
at java.time.format.DateTimeFormatter.createError(Unknown Source)
at java.time.format.DateTimeFormatter.parse(Unknown Source)
at java.time.LocalDateTime.parse(Unknown Source)
at Main.main(Main.java:9)
Caused by: java.time.DateTimeException: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 00:00 of type java.time.format.Parsed
at java.time.LocalDateTime.from(Unknown Source)
at java.time.format.Parsed.query(Unknown Source)
... 3 more
Caused by: java.time.DateTimeException: Unable to obtain LocalDate from TemporalAccessor: {},ISO resolved to 00:00 of type java.time.format.Parsed
at java.time.LocalDate.from(Unknown Source)
... 5 more
我想将格式为“小时:分钟”的字符串解析为本地日期时间(24 小时格式)。我不在乎分配什么月/年/日,我只想要时间。
【问题讨论】:
-
您的数据“00:00”似乎与 ISO_LOCAL_TIME 规定的格式不兼容。
标签: java