在下面的代码中,当我从日期中减去天时,我得到的天和月都减一。
var today = new Date();
today.setDate(today.getDate() - 1);
var dd = today.getDate();
var mm = today.getMonth() + 1; //Here is the problem so I have to do +1 to get to current month
var yyyy = today.getFullYear();
有人知道为什么会发生这种情况吗?或者,如果我以错误的方式做,任何人都可以建议正确的方法吗?
最佳答案
使用javascript的date.getMonth()
方法,月份是0-11,这里没有任何问题
关于javascript - 在 Javascript 中减去日期也减去月份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25201910/