开发者

Difference in Javascript Date object

开发者 https://www.devze.com 2023-03-14 01:19 出处:网络
Depending on how you create a Date object a different timestamp is returned. var g1 = new Date(201开发者_如何学C1, 6, 18, 14, 50, 0);

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());
0

精彩评论

暂无评论...
验证码 换一张
取 消