当前位置:网站首页>Reasons and solutions for the 8-hour difference in mongodb data date display
Reasons and solutions for the 8-hour difference in mongodb data date display
2022-07-04 10:05:00 【gblfy】
List of articles
One 、 See the essence through the phenomenon
1. Background research
Recently, because the project needs to use MongoDB, Use Navicat Premium 15 Client visualizer queries data , But here's the problem , The inserted data shows a difference when viewing 8 Hours , But the program passed new Date() To generate time , System time confirmation is ok , After many tests, it is found that the date obtained by the program call is no problem , Then it can only be the display problem of the client program .
- The normal time is :
2022-07-03 12:38:11
- Actual storage time
2022-07-03 04:38:11
2. Cause analysis
Time zone difference :
Stored in mongodb The time in is the standard time UTC +0:00, The time zone of China is +8.00
explain :UTC namely Universal Time Coordinated, namely 0 The time zone is different from the East eighth District 8 Hours .
3. Impact Assessment
1. Database query data -> Show problems
2. The query data is incorrect -> The return data of the page is also less 8 Hours
Two 、 Solution
2.1. Client display problem
Download visualization tools Robo3T
open Robo3T;
- Click on Options -> display dates in… You can see that there is 2 An option :
- 1.UTC( Default )
- 2.Local TimeZone.
- choice Local TimeZone, Check the data time again , It is found that it is normal .
notes :UTC namely Universal Time Coordinated, namely 0 The time zone is different from the East eighth District 8 Hours .
2.2. The query data is incorrect
Add @JsonFormat Annotation and configuration
@JsonFormat(locale = "zh", timezone = "Asia/Shanghai", pattern = "yyyy-MM-dd HH:mm:ss")
@Field("createTime")
private Date createTime; // Message creation time
2.3. Effect validation
Client display problem
The front end receives messages
Return time attribute :createTime
[{
"id": "62c11d3435b7c4007a8e650e",
"fromUserId": "21100598TZ9XG6RP",
"fromNickname": " Little beauty ",
"fromFace": "http://gblfy.cn:9000/imooc/xh.jpg",
"toUserId": "220620BZ2DH0KP94",
"msgType": 1,
"msgContent": {
"isFriend": true
},
"createTime": "2022-07-03 12:38:11"
},
... Other data are ignored
]
- The normal time is :
2022-07-03 12:38:11
test result : The return data time is consistent with the correct drop
边栏推荐
- Exercise 7-8 converting strings to decimal integers (15 points)
- Exercise 9-5 address book sorting (20 points)
- PHP代码审计3—系统重装漏洞
- Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)
- PHP personal album management system source code, realizes album classification and album grouping, as well as album image management. The database adopts Mysql to realize the login and registration f
- leetcode1-3
- 按键精灵打怪学习-识别所在地图、跑图、进入帮派识别NPC
- C language pointer classic interview question - the first bullet
- Hands on deep learning (35) -- text preprocessing (NLP)
- Summary of small program performance optimization practice
猜你喜欢
uniapp 小于1000 按原数字显示 超过1000 数字换算成10w+ 1.3k+ 显示
Application of safety monitoring in zhizhilu Denggan reservoir area
SSM online examination system source code, database using mysql, online examination system, fully functional, randomly generated question bank, supporting a variety of question types, students, teache
C language pointer interview question - the second bullet
华为联机对战如何提升玩家匹配成功几率
Hands on deep learning (46) -- attention mechanism
Qtreeview+ custom model implementation example
六月份阶段性大总结之Doris/Clickhouse/Hudi一网打尽
Pcl:: fromrosmsg alarm failed to find match for field 'intensity'
QTreeView+自定义Model实现示例
随机推荐
Hands on deep learning (34) -- sequence model
Hands on deep learning (38) -- realize RNN from scratch
百度研发三面惨遭滑铁卢:面试官一套组合拳让我当场懵逼
C # use smtpclient The sendasync method fails to send mail, and always returns canceled
SSM online examination system source code, database using mysql, online examination system, fully functional, randomly generated question bank, supporting a variety of question types, students, teache
Hands on deep learning (35) -- text preprocessing (NLP)
Hands on deep learning (45) -- bundle search
什么是 DevSecOps?2022 年的定义、流程、框架和最佳实践
How to teach yourself to learn programming
How to display √ 2 on the command line terminal ̅? This is actually a blog's Unicode test article
`Example of mask ` tool use
Hands on deep learning (42) -- bi-directional recurrent neural network (BI RNN)
Devop basic command
Hands on deep learning (33) -- style transfer
Baidu R & D suffered Waterloo on three sides: I was stunned by the interviewer's set of combination punches on the spot
Write a jison parser from scratch (3/10): a good beginning is half the success -- "politics" (Aristotle)
Go context 基本介绍
C # use gdi+ to add text with center rotation (arbitrary angle)
In the case of easyUI DataGrid paging, click the small triangle icon in the header to reorder all the data in the database
入职中国平安三周年的一些总结