2

Depending on how you create a Date object a different timestamp is returned.

var g1 = new Date(2011, 6, 18, 14, 50, 0);
var g2 = new Date("June 18, 2011 14:50:00");
alert(g1.getTime() + "\n" + g2.getTime());

// velue alerted is 
1310997000000
1308405000000

Any thoughts?

1 Answer 1

4

According to the documentation for Date:

month

Integer value representing the month, beginning with 0 for January to 11 for December

You are passing 6 for the month, so the constructor interprets it as July.

Both of these values should be identical:

var g1 = new Date(2011, 5, 18, 14, 50, 0);
var g2 = new Date("June 18, 2011 14:50:00"); 

alert(g1.getTime() + "\n" + g2.getTime());
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot ! This makes perfect sense now.
You're welcome. Its always fun dealing with those little off-by-one errors when working with date/time :)

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.