SpringBoot返回date日期格式化
SpringBoot返回date日期格式化,解决返回为TIMESTAMP时间戳格式或8小时时间差
问题描述
在Spring Boot项目中,使用@RestController注解,返回的java对象中若含有date类型的属性,则默认输出为TIMESTAMP时间戳格式(数据库datetime类型查询出来就是时间戳) ,如下所示:
解决方案
解决方案有多种,这里只记录本人觉得最简单的一种。一般我们的日期显示格式为:yyyy-MM-dd HH:mm:ss,所以我们可以在配置文件中进行全局配置。
在application.properties配置文件增加以下配置::
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
第一行指定date输出格式为yyyy-MM-dd HH:mm:ss;
第二行指定时区,解决8小时的时间差问题。
运行结果:
参照上面的方式如果还还是解决不了,可以在实体类上加上 下面这个注解

参考:https://blog.csdn.net/beauxie/article/details/78552919
springboot2.0后,spring会将时间自动给转成UTC字符串了
springboot1.x版本的将date字段返回的是时间戳
配置返回时间戳
spring
jackson:
serialization:
write-dates-as-timestamps: true
全局配置返回字符串
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
SpringBoot返回date日期格式化的更多相关文章
- SpringBoot返回date日期格式化,解决返回为TIMESTAMP时间戳格式或8小时时间差
问题描述 在Spring Boot项目中,使用@RestController注解,返回的java对象中若含有date类型的属性,则默认输出为TIMESTAMP时间戳格式 ,如下所示: 解决方案 ...
- Date 日期格式化
<span id="time"></span> <script> //名称:日期加法函数 //参数:part(year.month.day.ho ...
- SpringBoot返回JSON日期格式问题
SpringBoot中默认返回的日期格式类似于这样: "birth": 1537407384500 或者是这样: "createTime": "201 ...
- js Date 日期格式化(转)
var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); //获取完整的年份(4位,1 ...
- js的 new Date()日期格式化显示以及js获取时间戳
一.日期格式化显示: 对 new Date() 得到日期的进行格式显示扩展,扩展方法如下: // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分 ...
- javascript Date 日期格式化 formatDate, require.js 模块 支持全局js引入 / amd方式加载
* 引入AMD加载方式: require.js CDN https://cdn.bootcss.com/require.js/2.3.5/require.js * 创建模块文件./js/util/d ...
- springboot 返回json字符串格式化问题
在idea中yml文件中添加以下注解就可以格式化json字符串效果 spring: jackson: serialization: indent-output: true 原返回json格式为: {& ...
- JS :Date日期格式化
Date.prototype.format = function (formatStr) { var date = this; /* 函数:填充0字符 参数:value-需要填充的字符串, lengt ...
- date日期 格式化
这个是别人写的,我拿过来用的,哈哈 Date.prototype.format = function(fmt) { var o = { "M+" : this.getMonth() ...
随机推荐
- 《电子计算机机房设计规范》GB50174-93
<电子计算机机房设计规范>GB50174-2008 http://gf.1190119.com/article-17886.htm 中华人民共和国国家标准 电子计算机机房设计规范 GB 5 ...
- c++ stl bind函数介绍
/* stl::bind 使用 */ #include <iostream> #include <string> #include <functional> /* ...
- Qt button按钮添加Label标签播放GIF图片
QPushButton btn = new QPushButton(); QVBoxLayout* layout = new QVBoxLayout(btn); QLabel* label = new ...
- 【SpringBoot】SpringBoot快速入门(一)
SpringBoot介绍 Spring Boot使创建可运行的独立,生产级基于Spring的应用程序变得容易.对Spring平台和第三方库整合,这样就可以以最小的麻烦开始使用.大多数Spring Bo ...
- Laya微信小游戏的开放域
版本2.1.1.1 现在Laya的开放域比较好用了. 新建开放域项目,里面直接有个排行榜的示例. 直接发布 得到较少的文件,复制这些文件,粘贴到主项目bin/openDataContext下. (op ...
- [转]彻底解决deepin linux的无线网络问题
链接地址:https://bbs.deepin.org/forum.php?mod=viewthread&tid=153154
- 动态字节码技术Javassist
字节码技术可以动态改变某个类的结构(添加/删除/修改 新的属性/方法) 关于字节码的框架有javassist,asm,bcel等 引入依赖 <dependency> <groupI ...
- [转帖]Introduction to Linux monitoring and alerting
Introduction to Linux monitoring and alerting https://www.redhat.com/sysadmin/linux-monitoring-and-a ...
- hdfs、tfs、fastdfs、Tachyon
hdfs 架构设计 HDFS按照Master和Slave的结构.分NameNode.SecondaryNameNode.DataNode这几个角色. NameNode:是Master节点,是管理者.. ...
- xorm -Exist方法实例
判断某个记录是否存在可以使用Exist, 相比Get,Exist性能更好. package main import ( "fmt" _ "github.com/go-sq ...