3 回答
TA贡献1806条经验 获得超5个赞
const Days=14
let result = new Date();
result.setDate(result.getDate() + Days);
console.log(result)
TA贡献1797条经验 获得超6个赞
既然你想在未来 98 天:
function daysInFuture(days, func, continuous = true){
requestAnimationFrame(()=>{
func(new Date(Date.now()+86400000*days));
if(continuous)daysInFuture(days, func, continuous);
});
}
addEventListener('load', ()=>{
const out = document.getElementById('out');
daysInFuture(98, factored=>{
out.textContent = factored.toString();
}/*, false (if you want to not be continuous) */);
}); // end load
<div id='out'></div>
TA贡献1807条经验 获得超9个赞
好的,下面是我的答案(对此很陌生,我意识到我的问题在很多方面都很糟糕并且没有显示研究等)感谢那些试图提供帮助的人,但我想出了我想做的事情,这是如何做的:
问题应该是:使用 javascript,如何显示未来 98 天的日期,以及如何分别显示部分日期并显示月份名称。
回答:
var month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var d = new Date();
var numberOfDaysToAdd = 98;
d.setDate(d.getDate() + numberOfDaysToAdd);
var n = month[d.getMonth()];
document.getElementById("month").innerHTML = n;
document.getElementById("day").innerHTML = d.getDate();
<p id="month"></p>
<p id="day"></p>
添加回答
举报