赞
踩
今天遇到一个要按周切换的时间选择器,简单的做一下记录
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(); },
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。