Reputation: 618
I have a website where dates are sent to and from the server using JSON.stringify(). If the client writes a comment it is sent to the server with a date string, which looks like this
"2013-09-21T04:00:00.000Z"
When the server gets the string I create a new date from the string
var server_date = new Date("2013-09-21T04:00:00.000Z");
This date variable is stored in a MongoDB. But when the client reloads the page the date string the client receives looks like
"2013-09-21T00:00:00.000Z"
And when I make a new date from this string on the client
var client_date = new Date("2013-09-21T00:00:00.000Z");
the date object is incorrect. Somehow when I set the client_date the date is set to 9/20/2013 rather than 9/21/2013. When running the server on my local machine this was never a problem. Currently the server is running on AWS so I'm assuming that this is somehow messing with the dates? But I don't understand how the client_date variable is set one day before the date specified in the string, regardless of the hours-min-seconds. How can I format my dates to fix this problem? Thanks!
Upvotes: 1
Views: 99
Reputation: 10627
Z
means Universal Time Coordinated (UTC) or Greenwich Mean Time (GMT). Therefore, when it's 2013-09-21T00:00:00.000Z
in Greenwich it's still the 20th of September west all the way to where your Client is.
Upvotes: 2