为什么一串数字的工作方式与 new Date() 中的实际数字不同:
var myfirstDate = new Date("2013, 10, 15"); //returns Tue Oct 15 2013 00:00:00 GMT-0500 (CDT)
var mysecondDate = new Date(2013, 9, 15); // also returns Tue Oct 15 2013 00:00:00 GMT-0500 (CDT)
myfirstDate.value == mysecondDate.value; //returns true
我看了几个教程,上面甚至没有提到像 myfirstDate 这样的字符串的想法。 JavaScript 会自动解析字符串吗?
最佳答案
参见the docs .
您实际上调用了两个不同的构造函数。
第一个被解析为人类可读的日期:
new Date(dateString)
第二个需要 3 个或更多参数,提供年份、基于 0 的月份数字和日期
new Date(year, month, day [, hour, minute, second, millisecond]);
year
Integer value representing the year. For compatibility (in order to avoid the Y2K problem), you should always specify the year in full; use 1998, rather than 98.
月份
Integer value representing the month, beginning with 0 for January to 11 for December.
日
block 引用>Integer value representing the day of the month (1-31).
关于javascript - 为什么一串数字的工作方式与新日期中的实际数字不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19414883/