时间字符串如下:2023-09-12T16:00:00.000+00:00
错误代码:
LocalDateTime orderTime1 = (LocalDateTime) o1.get("create_time");
解决办法:
(1)、先转换成yyyy-MM-dd HH:mm:ss格式
String localDate1 = LocalDateTime .parse(orderTime1, DateTimeFormatter.ISO_OFFSET_DATE_TIME) .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
(2)、再将字符串( yyyy-MM-dd HH:mm:ss)转换成LocalDateTime
LocalDateTime localDateTime1=LocalDateTime.parse(localDate1, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
修改如下:
String orderTime1 = (String) o1.get("create_time"); String localDate1 = LocalDateTime .parse(orderTime1, DateTimeFormatter.ISO_OFFSET_DATE_TIME) .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); LocalDateTime localDateTime1=LocalDateTime.parse(localDate1, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
知识小贴士:
2022-06-25T00:00:00 转换成 yyyy-MM-dd格式
String date = LocalDateTime .parse("2022-06-25T00:00:00", DateTimeFormatter.ISO_DATE_TIME) .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));