Bill Software Engineer
Bill Software Engineer

Reputation: 7822

JS date object is not parsing correctly

We currently save the date in this format: 12/12/2011 8:00:00 PM.

When I parse it in JS Date object, it converts into this: Tue, 13 Dec 2011 00:00:00 GMT.

I do not believe this is a timezone issue because we are -4 GMT and it does not add up. Any ideas?

var start = new Date("12/12/2011 8:00:00 PM");
alert("12/12/2011 8:00:00 PM");
alert(start.toUTCString());

Upvotes: 0

Views: 182

Answers (1)

Aaron J Spetner
Aaron J Spetner

Reputation: 2155

It seems to add up perfectly. "12/12/2011 8:00:00 PM" in GMT-4 is exactly "Tue, 13 Dec 2011 00:00:00 GMT".

EDIT Use toLocaleString to get the date and time in your local time zone.

start.toLocaleString()

Upvotes: 4

Related Questions