【发布时间】:2014-06-19 17:00:59
【问题描述】:
我相信很多人都问过这个问题,但是当我检查答案时,我觉得他们的发现是错误的
var startDate = new Date(Date.parse(startdate));
//The start date is right lets say it is 'Mon Jun 30 2014 00:00:00'
var endDate = new Date(startDate.getDate() + 1);
// the enddate in the console will be 'Wed Dec 31 1969 18:00:00' and that's wrong it should be 1 july
我知道.getDate()从1-31返回,但是浏览器或javascript是否只增加一天而不更新月份和年份?
在这种情况下我应该写一个算法来处理这个吗?还是有别的办法?
【问题讨论】:
-
你正在有效地做
enddate = new Date(30+1)->new Date(31)。 JS 究竟应该如何知道 31 是什么? -
getDate()only 返回月份中的哪一天。它没有返回任何关于月/年的信息 -
请再次阅读问题
标签: javascript date