记录代码生成2020-7-8这种日期格式的代码

let now = new Date();
    let morr = new Date(now.getTime() + (60 * 60 * 24 * 1000) * 1 );
    let dateList = ['周日','周一','周二','周三','周四','周五','周六']
    this.data.dataTime.push({day:"明天",time:morr.getFullYear() + '-' + (morr.getMonth() + 1) + '-' + morr.getDate()})
    for(let i = 2; i <= 7;i++){
      var getTime = new Date(now.getTime() + (60 * 60 * 24 * 1000) * i);
      this.data.dataTime.push({day:dateList[getTime.getDay()],time:getTime.getFullYear() + '-' + (getTime.getMonth() + 1) + '-' + getTime.getDate()})
    }
    this.setData({
      dataTime:this.data.dataTime
    })

效果
在这里插入图片描述

你可能感兴趣的:(js,微信小程序)