【发布时间】:2022-11-21 02:00:12
【问题描述】:
我在从 txt 读取日期部分并将它们定义为对象中的 localdate 时遇到问题。
以下是 txt 文件中的示例值。
1-11-2022
11-10-2022
3-12-2022
...
这是下面显示的代码 sn-ps。
static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
...
object.setDate(LocalDate.parse(objectValue[0], formatter)); // HERE IS ERROR
...
这是下面显示的错误。
Exception in thread "main" java.time.format.DateTimeParseException: Text '1-11-2022' could not be parsed at index 0
我该如何解决?
【问题讨论】:
-
我现在没有时间检查这个,因此不是答案:但是你已经按照要求的格式写了“dd”;我认为这意味着输入时至少需要两位数字。