Difference in Javascript Date object
Depending on how you create a Date object a different timestamp is returned.
var g1 = new Date(201开发者_如何学C1, 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?
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());
精彩评论