Https://github.com/ewcmsfree/ewcms/wiki/Help-mongo-java-driver-date
The Mongo storage date is a 64-bit integer number. When the Java driver saves the date, it will automatically convert it to the standard time GMT. For example, in GMT + 8 time zone in China, save 00:00:00 to the database. The query result is 16:00:00, which is inconsistent with the expected result. You can find the root cause of the problem in COM. MongoDB. util. JSON:
if (o instanceof Date) { Date d = (Date) o; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT"))); serialize(new BasicDBObject("$date", format.format(d)), buf); return; }
You can easily find the question and convert the date by yourself:
Simpledateformat
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT"))); Date date = format.parse("2012-01-20 00:00:00");
The date is changed to 08:00:00 + 08, that is, 8 hours are automatically added in GMT + 8 time zone.