[Time Zone] The query date or insertion date is 8 hours less than the current time

In a development, it was found that the create_time or update_time inserted into the database was 8 hours less.

It is natural to think of the issue of time zones.

Go to the server to check the server time. . .

 

The server's time is found to be normal.

Then go to the database to see the time. . . .

 

The time to discover the database is also normal. .

Then I went to check the SQL statement generated by mybatis , and found that the parameters on the SQL statement were already missing by 8 hours. .

If the database entry time is normal, when fetching data, Jackson is used to parse and serialize the json, and convert the java data to json or xml or vice versa. At this time, the date needs to be formatted, as follows:

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date updateTime;


Jackson's global configuration can also be configured, and the time zone of Jackson can be configured in the configuration file, as follows:

jackson:
    time-zone: GMT+8

Guess you like

Origin blog.csdn.net/wufaqidong1/article/details/129651508