简体   繁体   中英

How to insert date in mongo DB without timezone

I am using the following date method to insert a date in mongo DB:

BasicDBObject Created_Date = new BasicDBObject("date", now);
record.put("Created_Date", now);

It returns the result in below format:

 "Created_Date" : ISODate("2017-10-11T06:16:10.536Z")

Is it possible to insert date without time zone ie

"Created_Date" :"2017-10-11"

Thanks for any help.

Your question is not consistent with your example. Your example shows storing the date without the time portion of the date, but your question is about storing the date without the timezone .

MongoDB doesn't store timezone as part of the date, all dates are stored in UTC. See Model Time Data for more details.

If you want to store the date without the time (as you show in your example), then "truncate" the date. You will still have a full Date object, with the time appearing as midnight UTC, but that's a fairly typical way of handling dates as you describe.

Since you're using Java, here are a few ways to truncate the date : Java Date cut off time information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM