您当前的位置: 首页 >  json

qq_34412985

暂无认证

  • 0浏览

    0关注

    1061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

解决@JsonFormat格式日期少一天问题

qq_34412985 发布时间:2019-04-11 16:25:23 ,浏览量:0

使用Jackson的@JsonFormat注解时出现少一天

比如数据库存的日期是2015-01-05,转成json则变成了2015-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;  }

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

/**   * 需要自定义时间格式化格式,否则会使用默认时间格式化 */ @JsonFormat (shape = JsonFormat.Shape.STRING, pattern ="yyyy-MM-dd HH:mm:ss")

关注
打赏
1653291990
查看更多评论
立即登录/注册

微信扫码登录

4.2678s