Reputation: 6953
I am storing date objects in mongodb. When I fetch them out, I get something like this:
"2016-10-18T10:53:31.851Z"
When I take that string and put it into a date function I get this:
Date("2016-10-18T10:53:31.851Z")
"Fri Nov 18 2016 14:15:44 GMT-0500 (EST)"
Note that the minutes and the seconds, and even the month looks incorrect. The hour looks like it is off by one. Why is that?
Upvotes: 2
Views: 74
Reputation: 2586
invoking Date in the way you are doing produces the current date and time. To create a variable based on that string, use
new Date("2016-10-18T10:53:31.851Z")
Tue Oct 18 2016 03:53:31 GMT-0700 (Pacific Daylight Time)
Upvotes: 8