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

2019-04-30  本文已影响0人  Do_Du
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 + '日'
    },
上一篇下一篇

猜你喜欢

热点阅读