美文网首页
计算当前天数前后n天的日期

计算当前天数前后n天的日期

作者: Do_Du | 来源:发表于2019-04-30 17:12 被阅读0次
    created() {
        this.dateInterval = this.countDay(7) + ' - ' + this.countDay(0)  // 结果:4月7日-4月14日
      },
    
    countDay(day) {
          var today = new Date() // 当天的时间
          var seconds = today.getTime() - 1000 * 60 * 60 * 24 * day  //当天的前后day天的时间戳
    
          var newDate = new Date(seconds)
          var month = newDate.getMonth() + 1
          var date = newDate.getDate()
          return month + '月' + date + '日'
        },
    

    相关文章

      网友评论

          本文标题:计算当前天数前后n天的日期

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