Spring boot+mongodb time inconsistency problem

      In the application, the creation time is set for an entity object, using the java.util.Date type, and directly generated by new Date(). After saving to Mongodb, it is found that the value of this field is 8 hours less, that is, 8 hours later than the actual saving time . The reason is because Mongodb saves the time in standard Greenwich Mean Time (GMT) , without setting the local time zone, and Beijing time belongs to the East Eighth District, which is eight hours earlier than it. In fact, the two time values ​​represent the same time, but the data returned during the query is not displayed normally. In order to display the time seen by the client as Beijing time, a json parsing time zone configuration can be added to the spring boot configuration file. That's it (jackson is used here as the json parsing framework, other frameworks are similar): spring.jackson.timeZone=GMT+8.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326266547&siteId=291194637