Mongdb's Datezone

Source: Internet
Author: User

First understand: Date itself is not formatted, just a number of milliseconds, to be displayed as a certain format must be a string

Https://github.com/ewcmsfree/ewcms/wiki/Help-mongo-java-driver-date

MONGO Java driver Date conversion issues

MONGO save date is a 64-bit number. Java driver will automatically convert to standard time GMT when saving date. such as China in the gmt+8 time zone, save 2012-01-20 00:00:00 to the library, the query results unexpectedly is 2012-01-19 16:00:00 with want results inconsistent. You can find the root cause of the problem in Com.mongodb.util.JSON:

if instanceof  =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 ;}


If you find a question, you can do it yourself. Conversion of Completion date: #SimpleDateFormat

New SimpleDateFormat ("Yyyy-mm-dd ' T ' HH:mm:ss. SSS ' Z '); Format.setcalendar ( new GregorianCalendar (new simpletimezone (0, "GMT"  ) = Format.parse ("2012-01-20 00:00:00");

Date dates become 2012-01-20 08:00:00+08 that is automatically added 8 hours in the gmt+8 time zone.


Or

Convert Date (GMT) to String (gmt+8)//JDK help us automatically add 8
The MONGO is responsible for turning string (gmt+8) into date (gmt+8)

When taken again, the date (GMT+8) is taken as a string (gmt+8)//mongo will not be responsible for the transfer

Mongdb's Datezone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.