0

As simple as this is I appear to be missing something in understanding the Date() object or im just too tired to see something obvious. Why does this javascript report the month wrong? (It will report the month as July instead of June as written.)

<script>

var x = new Date(2013,6,27,0,0,0,0);
var today = new Date();

if (x>today)
  {
  alert("Today is before " + x);
  }
else
  {
  alert("Today is after " + x);
  }

</script>

enter image description here

4

3 回答 3

3

因为在JS个里去011看的Date Object

您必须将代码更改为:

new Date(2013, 5, 27, 0, 0, 0, 0);
于 2013-05-28T13:36:07.007 回答
3

JavaScript 从 0 开始计算月份

于 2013-05-28T13:36:12.983 回答
0

请忽略,我没有深入了解,答案已经出现在 SO 上:

Javascript Date.UTC() 函数关闭了一个月?

谢谢。

于 2013-05-28T13:37:27.417 回答