当前位置:网站首页>@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 latest masterpiece!Alibaba just released the interview reference guide (Taishan version), I just brushed it for 29 days
- VOT2021比赛简介
- 架构实战营模块 8 作业
- 一款国外开发的高质量WordPress下载站模板主题
- A few permanent free network transmission, convenient and simple (Intranet through tutorials)
- Judging decimal points and rounding of decimal operations in Golang
- Pytest初体验
- HTC使用官方固件作为底包制作rom卡刷包教程
- 标段参数说明
- Pytorch lstm time series prediction problem stepping on the pit "recommended collection"
猜你喜欢
![[Code Hoof Set Novice Village 600 Questions] Leading to the combination of formulas and programs](/img/91/63d4f7869e0a55d19701c5ca5c9ed8.png)
[Code Hoof Set Novice Village 600 Questions] Leading to the combination of formulas and programs

Binary tree non-recursive traversal

Chapter Six

Go1.18 upgrade function - Fuzz test from scratch in Go language

财务盈利、偿债能力指标

Summary of the classic drawing method of histogram
![[Intensive reading of the paper] iNeRF](/img/a7/910667911e1ce8996b9d22de63ea04.png)
[Intensive reading of the paper] iNeRF

Flex layout in detail

Redis Overview: Talk to the interviewer all night long about Redis caching, persistence, elimination mechanism, sentinel, and the underlying principles of clusters!...

The difference between adding or not adding the ref keyword when a variable of reference type is used as a parameter in a method call in C#
随机推荐
Commonly used security penetration testing tools (penetration testing tools)
Document management and tools in the development process
Socket回顾与I/0模型
BM5 merge k sorted linked lists
Architecture Battalion Module 8 Homework
focus on!Haitai Fangyuan joins the "Personal Information Protection Self-discipline Convention"
[QNX Hypervisor 2.2用户手册]9.14 set
Thymeleaf是什么?该如何使用。
A shortcut to search for specific character content in idea
grep command written test questions
网易云信圈组上线实时互动频道,「破冰」弱关系社交
了解下C# 匿名方法
Write a database document management tool based on WPF repeating the wheel (1)
useragent online lookup
VOT2021比赛简介
LeetCode 第 304 场周赛
利用反射实现一个管理对象信息的简单框架
支付模块实现
Basic configuration of OSPFv3
uniapp小程序检查、提示更新