我很难找到解析日期的正确方法。我收到的日期是以下格式的字符串:'2018-10-18 00:00:00'我需要将其转换为 18/10/2018 并存储在变量 startDate 中然后我需要一个新变量来保存 endDate 变量,以便将日期向前滚动一周。我的代码:public String getStartDate(String startDate){ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); LocalDate localStartDate = LocalDate.parse(startDate, formatter); String startDateFormatted = localStartDate.format(formatter); return startDateFormatted;}public LocalDate getEndDate(String startDate) { LocalDate localEndDate = LocalDate.parse(getStartDate(startDate)).plusDays(7); return localEndDate;}我的错误是:java.time.format.DateTimeParseException: Text '2018-10-18 00:00:00' could not be parsed at index 4索引 4 建议使用“-”字符。不确定用于删除原始字符串中的 ISO 时间格式的格式化程序模式我现在正在浏览 Javadocs,但谁能告诉我如何解决?
添加回答
举报
0/150
提交
取消