0
我有一個奇怪的問題,解析字符串到localdatetime解析字符串localdatetime
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
我想與格式解析字符串「時:分」到一個localdatetime(24H格式)。我不在乎每月/每年/每天是什麼樣的,我只想要時間。
似乎您的數據「00:00」與ISO_LOCAL_TIME強加的格式不兼容。 – user1929959