2 回答
TA贡献1848条经验 获得超6个赞
替代计算:
<script>
console.clear();
var log = console.log;
var d = new Date();
var daysToAdd = 5; //for example
var msInDay = 1000 * 60 * 60 * 24; //milliseconds in day
log("Before:",d.toLocaleString());
//add 5 days
d.setTime(d.getTime() + daysToAdd * msInDay);
//
log("After :",d.toLocaleString());
// alternative
log()
var d = new Date();
log("Before:",d.toLocaleString());
// add 5 days
d = new Date(d.getFullYear(),d.getMonth(),d.getDate()+5);
//
log("After :",d.toLocaleString());
// Note: can add hours, minutes, seconds if needed.
</script>
TA贡献1820条经验 获得超9个赞
var log = console.log;
var d = new Date();
var daysToAdd = 5; //for example
var msInDay = 1000 * 60 * 60 * 24; //milliseconds in day
log("Before:",d.toLocaleString());
//add 5 days
d.setTime(d.getTime() + daysToAdd * msInDay);
//
log("After :",d.toLocaleString());
添加回答
举报