`
kanpiaoxue
  • 浏览: 1744770 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

springboot 返回JSON日期格式问题

阅读更多

springboot返回的时间格式,根据版本的不同,可能返回时间戳,还可能返回UTC时间格式。

如: "createTime": 1537407384500 或者 "createTime": "2018-09-18T10:54:06.000+0000"

如何定制化springboot返回的时间格式呢?

修改 application.properties/yml 里面的配置即可。

spring:
    jackson:
        date: yyyy-MM-dd HH:mm:ss
        time-zone: GMT+8
        serialization:
            write-dates-as-timestamps: false

上面的是全局的时间格式化配置,如果要想在某个特定的接口返回特定的时间格式,如何处理?

@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
private Date createTime;

  如上,可以在时间字段上面添加 @JsonFormat 来指定时间格式。

 

 

参考资料:

1、https://blog.csdn.net/jeikerxiao/article/details/86217807

2、https://www.baeldung.com/spring-boot-formatting-json-dates

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics