我有以下脚本将在第二天返回:
function today(i)
{
var today = new Date();
var dd = today.getDate()+1;
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
today = dd+'/'+mm+'/'+yyyy;
return today;
}
通过使用此:
today.getDate()+1;
我要到本月的第二天(例如今天要16点)。
我的问题是,这可能是在该月的最后一天,因此最终返回32/4/2014
有什么办法可以保证第二天的正确日期?
您可以使用:
var tomorrow = new Date();
tomorrow.setDate(new Date().getDate()+1);
例如,由于四月有30天,因此以下代码将输出5月1日:
var day = new Date('Apr 30, 2000');
console.log(day); // Apr 30 2000
var nextDay = new Date(day);
nextDay.setDate(day.getDate() + 1);
console.log(nextDay); // May 01 2000
见小提琴。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句