当前位置:网站首页>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
边栏推荐
- mmclassification 标注文件生成
- 2. Data type
- Write a jison parser from scratch (1/10):jison, not JSON
- uniapp 小于1000 按原数字显示 超过1000 数字换算成10w+ 1.3k+ 显示
- Button wizard business running learning - commodity quantity, price reminder, judgment Backpack
- IIS configure FTP website
- Hands on deep learning (37) -- cyclic neural network
- 法向量点云旋转
- Write a jison parser from scratch (3/10): a good beginning is half the success -- "politics" (Aristotle)
- Vanishing numbers
猜你喜欢
对于程序员来说,伤害力度最大的话。。。
Hands on deep learning (45) -- bundle search
智能网关助力提高工业数据采集和利用
基于线性函数近似的安全强化学习 Safe RL with Linear Function Approximation 翻译 1
5g/4g wireless networking scheme for brand chain stores
Daughter love in lunch box
uniapp 小于1000 按原数字显示 超过1000 数字换算成10w+ 1.3k+ 显示
【Day1】 deep-learning-basics
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
How can people not love the amazing design of XXL job
随机推荐
Nuxt reports an error: render function or template not defined in component: anonymous
Devop basic command
xxl-job惊艳的设计,怎能叫人不爱
Application of safety monitoring in zhizhilu Denggan reservoir area
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
Lavel document reading notes -how to use @auth and @guest directives in lavel
Write a jison parser from scratch (2/10): learn the correct posture of the parser generator parser generator
2021-08-10 character pointer
回复评论的sql
Modules golang
MySQL transaction mvcc principle
System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
MySQL develops small mall management system
MongoDB数据日期显示相差8小时 原因和解决方案
5g/4g wireless networking scheme for brand chain stores
`Example of mask ` tool use
今日睡眠质量记录78分
C language pointer interview question - the second bullet
基于线性函数近似的安全强化学习 Safe RL with Linear Function Approximation 翻译 1
Hands on deep learning (44) -- seq2seq principle and Implementation