我想知道是否有可能解析时钟时间:分钟:秒在Java 8中?
例如:
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
final String str = "12:22:10";
final LocalDateTime dateTime = LocalDateTime.parse(str, formatter);我试过了但得到了这个例外:
Exception in thread "main" java.time.format.DateTimeParseException: Text '12:22:10' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 12:22:10 of type java.time.format.Parsed发布于 2016-10-05 09:38:41
LocalTime.parse
因为您只有一段时间使用LocalTime类。在您的情况下,不需要定义格式模式。
String str = "12:22:10";
LocalTime time = LocalTime.parse(str);请看代码在IdeOne.com现场运行。
有关更多信息,请参见Oracle教程。
发布于 2021-08-01 20:46:01
LocalTime.parse("04:17");
https://stackoverflow.com/questions/39870160
复制相似问题