当前位置:   article > 正文

按周切换的时间选择器_按周选择

按周选择

今天遇到一个要按周切换的时间选择器,简单的做一下记录

onShow: function () {
      let curD = new Date();
      let firstD = new Date();
      let lastD = new Date();
      this.setData({
            curD: curD,
            firstD: firstD,
            lastD: lastD
      })
      this.getTime()
},

getTime() {  //获取当前周
      let curD = this.data.curD
      let firstD = this.data.firstD
      let lastD = this.data.lastD
      let intD = new Date();
      let dayTime = 24 * 60 * 60 * 1000;
      var dateLong = curD.getTime();
      if (curD.getDay() == 0) { //当前时间取代过去的时间
            dateLong = dateLong - (6 * dayTime);
      } else {
            dateLong = dateLong - (curD.getDay() - 1) * dayTime;
      }
      let d = curD.setTime(dateLong);
      let tt = Date.parse(firstD)
      firstD = curD;
      lastD.setTime(firstD.getTime() + 6 * dayTime);
      let st = firstD.getFullYear() + '-' + (firstD.getMonth() + 1) + '-' + firstD.getDate();
      if (tt > Date.parse(st)){
            st = intD.getFullYear() + '-' + (intD.getMonth() + 1) + '-' + intD.getDate();
      }
      let ss = st + ' 至 ' + lastD.getFullYear() + '-' + (lastD.getMonth() + 1) + '-' + lastD.getDate();
      
      this.setData({
            ss: ss
      })
},

backDate() {  //上一周
      let curD = this.data.curD
      let dayTime = 24 * 60 * 60 * 1000;
      var dateLong = curD.getTime();
      curD.setTime(dateLong - (6 * dayTime));
      this.setData({
            curD: curD
      })
     this. getTime();
},
nextDate() {  //下一周
      let curD = this.data.curD
      let dayTime = 24 * 60 * 60 * 1000;
      var dateLong = curD.getTime();
      curD.setTime(dateLong + (7 * dayTime));
      this.setData({
            curD: curD
      })
      this.getTime();
},
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/679974
推荐阅读
相关标签
  

闽ICP备14008679号