标签: datetimeparseexception

ZonedDateTime 格式和解析格式模式中带有“z”的异常

我在解析时遇到问题ZonedDateTime

DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-ddzhh:mm");
ZonedDateTime.parse(s, formatter);
Run Code Online (Sandbox Code Playgroud)

这会导致错误:

java.time.format.DateTimeParseException:
    Text '2022-05-24UTC12:15' could not be parsed at index 10
Run Code Online (Sandbox Code Playgroud)

这段代码有什么问题吗?

java datetime-parsing java-time zoneddatetime datetimeparseexception

6
推荐指数
1
解决办法
1115
查看次数

解析 LocalDate 但得到 DateTimeParseException;dd-MMM-uuuu

我正在尝试将 a 转换StringLocalDateusing DateTimeFormatter,但收到异常:

java.time.format.DateTimeParseException:无法在索引 5 处解析文本“ 2021-10-31 ”

我的代码是

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MMM-uuuu");
String text = "2021-10-31";
LocalDate date = LocalDate.parse(text, formatter);
Run Code Online (Sandbox Code Playgroud)

我正在尝试从输入日期转换2021-10-3131-Oct-2021.

java java-time localdate datetimeformatter datetimeparseexception

4
推荐指数
1
解决办法
856
查看次数