閉關(guān)修行中......
Date type data in MongoDB only saves absolute time values ??and does not save time zone information, so the "displayed time" depends on the MongoDB client settings.
Based on the screenshot, I guess Robomongo is used. You can set the display of local time through "Options" - "Display Dates in..." - "Local Timezone".
mongoDB
默認按照UTC
來存儲時間,而我們中國所處時區(qū)通常叫做“東八區(qū)”,意思是UTC + 8
, so as you said, the deposit time seems to be "8 hours earlier" than it actually is. Documentation
Perhaps you can try setting the default time zone of the application when it starts?
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
Because it’s useless
java
操作過mongoDB
, I can’t guarantee it’s absolutely correct, but you can try it
The time you saved is the time of your server. Is it displayed normally? Does it mean it is consistent with the local time? Then you need to calculate the time zone and add the time difference when saving.