8 hour question
Phenomenon
- The time of inserting into the database is inconsistent with the input from the front end
- Inconsistencies displayed by database queries to the front end
reason
- Database time zone, software environment time zone, mysql-connector-java time zone, time-zone set by @RequestBody and @ResponseBody
Solution
- unified time zone
- database time zone
show variables like '%time_zone%';
查询结果为表示东八区(也就是咱们用的)
'time_zone','+08:00'
- software environment time zone
//linux
date -R
查询结果为表示东八区(也就是咱们用的)
Wed, 20 May 2020 21:50:23 +0800
- mysql-connector-java connection settings
spring:
datasource:
url: jdbc:mysql://ip:端口/db?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=Asia/Shanghai
- If you use json front-end interaction
序列化和反序列化的时候设置日期的处理
spring:
jackson:
time-zone: GMT+8