当前位置:网站首页>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
边栏推荐
- How do microservices aggregate API documents? This wave of show~
- 基于线性函数近似的安全强化学习 Safe RL with Linear Function Approximation 翻译 1
- 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
- Qtreeview+ custom model implementation example
- JDBC and MySQL database
- Histogram equalization
- 百度研发三面惨遭滑铁卢:面试官一套组合拳让我当场懵逼
- 2021-08-11 function pointer
- uniapp---初步使用websocket(长链接实现)
- Pueue data migration from '0.4.0' to '0.5.0' versions
猜你喜欢
pcl::fromROSMsg报警告Failed to find match for field ‘intensity‘.
Matlab tips (25) competitive neural network and SOM neural network
El Table Radio select and hide the select all box
leetcode1-3
Work order management system OTRs
Some summaries of the third anniversary of joining Ping An in China
Daughter love in lunch box
What are the advantages of automation?
Regular expression (I)
Hands on deep learning (43) -- machine translation and its data construction
随机推荐
ASP. Net to access directory files outside the project website
Write a jison parser from scratch (2/10): learn the correct posture of the parser generator parser generator
5g/4g wireless networking scheme for brand chain stores
Exercise 8-10 output student grades (20 points)
六月份阶段性大总结之Doris/Clickhouse/Hudi一网打尽
C # use gdi+ to add text with center rotation (arbitrary angle)
AUTOSAR从入门到精通100讲(106)-域控制器中的SOA
System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
Lauchpad X | 模式
Summary of reasons for web side automation test failure
pcl::fromROSMsg报警告Failed to find match for field ‘intensity‘.
Golang Modules
PHP student achievement management system, the database uses mysql, including source code and database SQL files, with the login management function of students and teachers
libmysqlclient. so. 20: cannot open shared object file: No such file or directory
2021-08-10 character pointer
Matlab tips (25) competitive neural network and SOM neural network
法向量点云旋转
Laravel文档阅读笔记-How to use @auth and @guest directives in Laravel
Write a jison parser from scratch (5/10): a brief introduction to the working principle of jison parser syntax
7-17 crawling worms (15 points)