获取当前日期

new Date().toLocaleDateString() // '2022/3/24'

 

获取到今日零点

new Date(new Date().toLocaleDateString()) // Thu Mar 24 2022 00:00:00 GMT+0800 (中国标准时间)

获取到今日零点的时间戳

new Date(new Date().toLocaleDateString()).getTime() // 1648051200000

以当前时间为基础,更改时间日期选择范围

changeDateRange (type) {
      let start = null
      let end = null
      const curDate = new Date(new Date().toLocaleDateString()).getTime()
      if (type === 'picker') {
        if (this.dateRange) {
          start = this.dateRange[0].getTime()
          end = this.dateRange[1].getTime() + 1000 * 3600 * 24 - 1
          this.text = ''
        } else this.text = 'all'
      } else {
        this.dateRange = ''
        switch (type) {
          // 当天
          case 'today':
            start = curDate
            end = curDate + 1000 * 3600 * 24 - 1
            break
          // 当周
          case 'week':
            start = curDate - 1000 * 3600 * 24 * 6 + 1
            end = curDate + 1000 * 3600 * 24 - 1
            break
          // 当月
          case 'month':
            start = curDate - 3600 * 1000 * 24 * 29 + 1
            end = curDate + 1000 * 3600 * 24 - 1
            break
          // 当年
          case 'year':
            start = curDate - 3600 * 1000 * 24 * 364 + 1
            end = curDate + 1000 * 3600 * 24 - 1
            break
          // 全部
          case 'all':
            start = ''
            end = ''
            break
          default:
            break
        }
      }
      this.start = start
      this.end = end
      this.initData()
    },
posted on 2022-03-24 18:13  蓝蓝蓝蓝HZ  阅读(34)  评论(0编辑  收藏  举报