当前位置:网站首页>@JsonFormat(pattern="yyyy-MM-dd") time difference problem
@JsonFormat(pattern="yyyy-MM-dd") time difference problem
2022-07-31 22:34:00 【HUAWEI CLOUD】
Recently, I was working on a course design project for a classmate,需要JavaThe backend returns the time to the frontend page、such as exam time、前端用的vue+element时间选择器、(use local time–北京时间),Backend time field mapping,转换,But the data will be transmitted to the background in less time than Beijing time8个小时.The specific check is because of the time zone problem.But the front-end display is still small8个小时,If so, there is definitely a problem.可以利用@JsonFormatBinding to object properties solves the problem.
原因:@JsonFormat(pattern=“yyyy-MM-dd”)时间差问题
解释:默认情况下timeZone为GMT(即标准时区),而北京是在东八区,所以会造成差8小时.
解决方法:加上timezone = "GMT+8
1 @JsonFormat(pattern=“yyyy-MM-dd HH:mm:ss”, timezone = “GMT+8”)
2 也可以在Springboot application.yml中修改MySQL配置
druid: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/renren_students?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai username: root password: 123456扩展知识:
注解@JsonFormat的使用
在项目maven引入@JsonFormat所需要的jar包.主要如下
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.8.8</version></dependency><dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.8.8</version></dependency><dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.13</version></dependency>@JsonFormat注解是一个时间格式化注解,比如我们存储在mysql中的数据是date类型的,当我们读取出来封装在实体类中的时候,就会变成英文时间格式,而不是yyyy-MM-dd HH:mm:ss这样的中文时间,因此我们需要用到JsonFormat注解来格式化我们的时间.It is generally used for a field name to be added to the attribute of the entity class corresponding to the corresponding query database object [email protected]属性.//设置时区为上海时区,时间格式自己据需求定.比如:@JsonFormat(pattern=“yyyy-MM-dd”,timezone = “GMT+8”).
大家点赞、收藏、关注、评论啦 、
边栏推荐
- STM32 full series development firmware installation guide under Arduino framework
- Dry goods | 10 tips for MySQL add, delete, change query performance optimization
- PHP三元(三目)运算符
- Getting Started with Tkinter
- Shell script quick start to actual combat -02
- cas and spin locks (is lightweight locks spin locks)
- 二叉树非递归遍历
- Collation of knowledge points in Ningbo University NBU IT project management final exam
- 关注!海泰方圆加入《个人信息保护自律公约》
- Binary tree non-recursive traversal
猜你喜欢

A shortcut to search for specific character content in idea
SQL27 View user details of different age groups

The principle of ReentrantLock (to be continued)

关注!海泰方圆加入《个人信息保护自律公约》
![[NLP] What is the memory of the model!](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[NLP] What is the memory of the model!

高效并发:Synchornized的锁优化详解

Student management system on the first day: complete login PyQt5 + MySQL5.8 exit the operation logic

Implementing a Simple Framework for Managing Object Information Using Reflection

Memblaze发布首款基于长存颗粒的企业级SSD,背后有何新价值?

MATLAB program design and application 2.4 Common internal functions of MATLAB
随机推荐
Redis Overview: Talk to the interviewer all night long about Redis caching, persistence, elimination mechanism, sentinel, and the underlying principles of clusters!...
A shortcut to search for specific character content in idea
基于STM32 环形队列来实现串口接收数据
#yyds干货盘点# 面试必刷TOP101:链表中环的入口结点
BM3 flips the nodes in the linked list in groups of k
Embedded development has no passion, is it normal?
关注!海泰方圆加入《个人信息保护自律公约》
Realization of character makeup
Short-circuit characteristics and protection of SiC MOSFETs
Memblaze released the first enterprise-grade SSD based on long-lasting particles. What is the new value behind it?
BM3 将链表中的节点每k个一组翻转
标段参数说明
【论文精读】iNeRF
The whole network is on the verge of triggering, and the all-round assistant for content distribution from media people - Rongmeibao
Architecture Battalion Module 8 Homework
Basic configuration of OSPFv3
Fixed-length usage of nanopb string type based on RT1052 Aworks (27)
Bika LIMS open source LIMS set - use of SENAITE (detection process)
STM32 full series development firmware installation guide under Arduino framework
What's wrong with the sql syntax in my sql