我的字符串值为08:03:10 pm,我想把它转换成时间.我怎么能用Java做到这一点?
我想知道是否有可能在Java 8中解析时钟时间:分钟:秒?
例如
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
final String str = "12:22:10";
final LocalDateTime dateTime = LocalDateTime.parse(str, formatter);
Run Code Online (Sandbox Code Playgroud)
我试过但得到这个例外:
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
Run Code Online (Sandbox Code Playgroud)