@DateTimeFormat
前端时间控件传值到后台,如,前端传了一个字符串 “2022-04-20 08:03:43”,后台转化为Date: Wed Apr 20 08:03:43 CST 2022,时间格式需要自己重新指定。
public class DateVo{
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date date;
}
@JsonFormat
后台指定时间格式给前端
jackson在序列化时间时是按照国际标准时间GMT进行格式化的,而在国内默认时区使用的是CST时区,两者相差8小时。所以还要加上 timezone = “GMT+8”
public class DateVo{
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date birthday;
}