在java中解析时钟时间8

编程入门 行业动态 更新时间:2024-10-10 15:28:15
本文介绍了在java中解析时钟时间8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

例如

我想知道是否有可能解析时钟时间: pre> final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(HH:mm:ss); final String str =12:22:10; final LocalDateTime dateTime = LocalDateTime.parse(str,formatter);

我试过但是得到这个例外:

<$线程main中的异常java.time.format.DateTimeParseException:Text '12:22:10'无法解析:无法从TemporalAccessor获取LocalDateTime:{},ISO已解析为12:22:10类型为java.time.format.Parsed

解决方案

由于您只有时间使用 LocalTime 类:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern( HH:mm:ss); String str =12:22:10; LocalTime time = LocalTime.parse(str,formatter);

请参阅 Oracle教程了解更多信息。

I wonder is it possible to parse clock time hour:minute:second in Java 8?

e.g.

final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); final String str = "12:22:10"; final LocalDateTime dateTime = LocalDateTime.parse(str, formatter);

I tried but get this exception:

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

解决方案

Since you only have a time use the LocalTime class:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); String str = "12:22:10"; LocalTime time = LocalTime.parse(str, formatter);

See Oracle Tutorial for more info.

更多推荐

在java中解析时钟时间8

本文发布于:2023-11-27 14:20:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638432.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时钟   时间   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!