我的記事本檔案中有文本:
19-12-2021
我檢查了是否有任何空格,沒有。
當我寫:
String noticeLastUpdateDate = textFileDAO.getMoneyTableNoticeLastUpdateDate();
DateTimeFormatter formatterDate = DateTimeFormatter.ofPattern("dd-MM-yyyy");
LocalDate dateNow = LocalDate.parse(noticeLastUpdateDate, formatterDate);
我收到一個錯誤:
java.time.format.DateTimeParseException: Text '19-12-2021
' could not be parsed, unparsed text found at index 10
但是沒有索引10!為什么它認為有索引[10]?
uj5u.com熱心網友回復:
在使用String::trim以下方法決議日期之前修剪可能的空格:
String trimmedDate = textFileDAO.getMoneyTableNoticeLastUpdateDate().trim();
DateTimeFormatter formatterDate = DateTimeFormatter.ofPattern("dd-MM-yyyy");
LocalDate dateNow = LocalDate.parse(trimmedDate, formatterDate);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/386773.html
