Reputation: 5150
If I submit the day as 5, the moth as 12 and the year as 1975 with the below function the output is "1975-12-04T16:00:00.000Z"
why is the day changed from the 5th to the 4th? and why is the hour 16? and the 2 extra milliseconds? What's going on?
if (req.body.year && req.body.month && req.body.day) {
dob = new Date(`${req.body.year}-${req.body.month}-${req.body.day}`);
dob.setHours(0, 0, 0, 0);
// dob then gets saved to mongo as a `Date`
}
The scema is defined as
dob: { type: Date },
Upvotes: 0
Views: 74
Reputation: 2679
I believe it is because mongo converts it to UTC. See the document.
MongoDB stores times in UTC by default, and will convert any local time representations into this form. Applications that must operate or report on some unmodified local time value may store the time zone alongside the UTC timestamp, and compute the original local time in their application logic.
Upvotes: 1