美文网首页
js获取当前时间前后7天,存入数组

js获取当前时间前后7天,存入数组

作者: 酸辣土豆丝g | 来源:发表于2019-01-26 21:13 被阅读0次
const temp = [];
for (let i = 0; i < 15; i++) {
    const time = new Date(new Date().setDate((new Date().getDate() + i) - 7));
    const year = time.getFullYear();
    const month = `0${time.getMonth() + 1}`.slice(-2);
    const strDate = `0${time.getDate()}`.slice(-2);
    temp.push(`${year}-${month}-${strDate}`)
}
console.log(temp);

相关文章

网友评论

      本文标题:js获取当前时间前后7天,存入数组

      本文链接:https://www.haomeiwen.com/subject/wplwjqtx.html