el-date-picker周选择器获取选择的日期范围

 el-date-picker周选择器获取选择的日期范围_第1张图片

 

 



// 方法一:
 weekChange(val) {
      let startTime = new Date(val.getTime()); //开始时间
      let endTime = new Date(val.getTime() + (24 * 60 * 60 * 1000) * 6); //结束时间
      let timeArr = [startTime.toISOString().slice(0, 10), endTime.toISOString().slice(0, 10)];
      console.log(timeArr)
    },
        
        
// 方法二:
  weekChange(val) {
      let timeStamp = val.getTime(); //标准时间转为时间戳,毫秒级别
      let startTimeStamp = this.getDateTime(timeStamp - 24 * 60 * 60 * 1000); //开始时间
      let endTimeStamp = this.getDateTime(timeStamp + (24 * 60 * 60 * 1000) * 5); //结束时间
      let timeArr = [startTimeStamp, endTimeStamp]
      console.log(timeArr)
    },
    getDateTime(dateTime) {
      var timeStamp = new Date(dateTime)
      var year = 1900 + timeStamp.getYear()
      var month = '0' + (timeStamp.getMonth() + 1)
      var date = '0' + timeStamp.getDate()
      return year + '-' + month.substring(month.length - 2, month.length) + '-' + date.substring(date.length - 2, date.length)
    } 

你可能感兴趣的:(后台管理系统,vue项目中常用操作,vue.js,elementui,javascript)