我用了ajax获取后端实体类的时间是java.util包的Date,通过template模板输出{{createTime}},不知道时间怎么格式化
通常两种方式,一个是在实体类里面,
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date time;
一个是在配置文件
#时间戳统一转换
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
。