报错信息
msg: “服务端异常,请联系管理员
JSON parse error: Cannot deserialize value of type java.util.Date
from String “2023-11-13 13:13:35”: not a valid representation (error: Failed to parse Date value ‘2023-11-13 13:13:35’: Cannot parse date “2023-11-13 13:13:35”: while it seems to fit format ‘yyyy-MM-dd’T’HH:mm:ss.SSSX’, parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type java.util.Date
from String “2023-11-13 13:13:35”: not a valid representation (error: Failed to parse Date value ‘2023-11-13 13:13:35’: Cannot parse date “2023-11-13 13:13:35”: while it seems to fit format ‘yyyy-MM-dd’T’HH:mm:ss.SSSX’, parsing fails (leniency? null))↵ at [Source: (PushbackInputStream); line: 1, column: 233] (through reference chain: com.java1234.entity.Product[“hotDateTime”])”
配置文件配置application.yml:
spring:
jackson:
#字符串时间,用这行表示
date-format: yyyy-MM-dd
#设置为东八区时间
timezone: GMT+8
spring:
# 配置日期格式化
jackson:
date-format: yyyy-MM-dd HH:mm:ss #时间戳统一转换为指定格式
time-zone: GMT+8 # 时区修改为东8区
application.properties配置方式
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss #时间戳统一转换为指定格式
spring.jackson.time-zone=GMT+8 # 时区修改为东8区
【注意】这里需要修改时区time-zone:数据库默认时区是格林尼治的时间,如果不设置,会比实际时间少8个小时(北京时间)。
项目场景:
前端画面上有一个可以选择年月的日期选择器,代码如下:
<el-form-item label="统计月份" prop="billsDate