【发布时间】:2017-10-06 19:48:23
【问题描述】:
这是 Visual Studio 即时窗口的输出。我从mondaysDate 开始,创建第二个日期thisDate,然后使用 mondaysDate 作为基数添加整数。
我不明白为什么将日期加 3 会产生 11 月 2 日,而将日期加 4 会产生 12 月 4 日。
多次调用 setDate() 是否违法?
?mondaysDate
Mon Oct 30 2017 00:00:00 GMT-0400 (Eastern Daylight Time)
?thisDate
Mon Oct 30 2017 00:00:00 GMT-0400 (Eastern Daylight Time)
?thisDate.setDate(mondaysDate.getDate() + 3)
1509595200000
?thisDate
Thu Nov 02 2017 00:00:00 GMT-0400 (Eastern Daylight Time)
?thisDate.setDate(mondaysDate.getDate() + 4)
1512363600000
?thisDate
Mon Dec 04 2017 00:00:00 GMT-0500 (Eastern Standard Time)
?mondaysDate
Mon Oct 30 2017 00:00:00 GMT-0400 (Eastern Daylight Time)
【问题讨论】:
-
当你说
date + 3时,你的意思是加3天、3个月、3年吗? -
我假设它正在增加天数:stackoverflow.com/questions/3818193/…
-
你期望的结果是什么?
-
我预计是 11 月 3 日而不是 12 月 4 日。
标签: javascript date-math