使用Jackson的@JsonFormat注解时出现少了 8 个小时

比如数据库存的日期是2018-01-05,转成json则变成了2018-01-04

解决办法:

@JsonFormat(pattern="yyyy-MM-dd")
 public Date getRegistDate() {
  return this.registDate;
 }

改成

@JsonFormat(pattern="yyyy-MM-dd",timezone="GMT+8")
 public Date getRegistDate() {
  return this.registDate;
 }

加上时区即可,中国是东八区

posted on 2018-06-30 17:19  零度千里  阅读(2067)  评论(0编辑  收藏  举报

导航