当前位置:网站首页>@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”).
大家点赞、收藏、关注、评论啦 、
边栏推荐
- The article you worked so hard to write may not be your original
- 一款国外开发的高质量WordPress下载站模板主题
- Memblaze released the first enterprise-grade SSD based on long-lasting particles. What is the new value behind it?
- Unity - LineRenderer show a line
- HTC using official firmware as bottom bag made ROM brush card bag tutorial
- Implementing a Simple Framework for Managing Object Information Using Reflection
- What's wrong with the sql syntax in my sql
- 登录业务实现(单点登录+微信扫码+短信服务)
- Pytest初体验
- 高通cDSP简单编程例子(实现查询高通cDSP使用率、签名),RK3588 npu使用率查询
猜你喜欢
focus on!Haitai Fangyuan joins the "Personal Information Protection Self-discipline Convention"
MATLAB program design and application 2.4 Common internal functions of MATLAB
Write a database document management tool based on WPF repeating the wheel (1)
The article you worked so hard to write may not be your original
Quick Start Tutorial for flyway
STM32 full series development firmware installation guide under Arduino framework
Getting Started with Tkinter
[NLP] What is the memory of the model!
高效并发:Synchornized的锁优化详解
Embedded development has no passion, is it normal?
随机推荐
Judging decimal points and rounding of decimal operations in Golang
角色妆容的实现
"The core concept of" image classification and target detection in the positive and negative samples and understanding architecture
Unity - LineRenderer show a line
Chapter VII
财务盈利、偿债能力指标
Niuke.com brush questions (1)
「APIO2010」巡逻 题解
21. Support Vector Machine - Introduction to Kernel Functions
UVM RAL model and built-in seq
"APIO2010" Patrol Problem Solution
[QNX Hypervisor 2.2用户手册]9.15 suppress
Flink_CDC construction and simple use
The uniapp applet checks and prompts for updates
What is Thymeleaf?How to use.
Shell script quick start to actual combat -02
Memblaze发布首款基于长存颗粒的企业级SSD,背后有何新价值?
Structure of the actual combat battalion module eight operations
Efficient Concurrency: A Detailed Explanation of Synchornized's Lock Optimization
支付模块实现