0

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());
3
  • 1
    8:00 PM is exactly 4 hours before 0:00. What's the problem? Commented Jan 4, 2012 at 21:53
  • Is the original date string meant to be in UTC/GMT as well? Cause, as is, Date assumes it to be a "local" date string. Commented Jan 4, 2012 at 22:01
  • Yes, what is wrong with that? 20:00:00 is 8pm. Commented Jan 4, 2012 at 22:03

1 Answer 1

4

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()
Sign up to request clarification or add additional context in comments.

3 Comments

I see... thanks for the answer. How do I convert it to my local GMT -4 if I need to use the getTime() functionality?
What is the output that you are looking for?
Actually it's correct, thanks, I forgot to take into account 12/24 hour display.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.