下面的代码,是我写小程序项目的片段,赋值给startTime是计算出来的日期,endTime默认当前日期,本文讲的是获取多少天前的日期,因此只需看那startTime就可以,希望能帮到大家!
//自由搜索 bindMoth: function(e) { var index = e.currentTarget.dataset.index;
this.setData({ activeIndex: index }) var name =
this.data.quarterData[index].name; var myDate = new Date(); if (name == '本月') {
this.setData({ saleOrderList: [], startTime: util.formatTime()[0] + '-' +
util.formatTime()[1] + '-' + "01", endTime: util.formatTime()[0] + '-' +
util.formatTime()[1] + '-' + util.formatTime()[2], pageSize: 10, pageIndex: 1
}) } else if (name == '50天') { //获取50天前日期 var date = new Date(myDate - 1000 *
60 * 60 * 24 * 50); var lastY = date.getFullYear(); var lastM = date.getMonth()
+ 1; var lastD = date.getDate(); this.setData({ saleOrderList: [], startTime:
lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" +
lastD : lastD), endTime: util.formatTime()[0] + '-' + util.formatTime()[1] +
'-' + util.formatTime()[2], pageSize: 10, pageIndex: 1 }) } else if (name ==
'100天') { //获取100天前日期 var date = new Date(myDate - 1000 * 60 * 60 * 24 * 100);
var lastY = date.getFullYear(); var lastM = date.getMonth() + 1; var lastD =
date.getDate(); this.setData({ saleOrderList: [], startTime: lastY + "-" +
(lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD),
endTime: util.formatTime()[0] + '-' + util.formatTime()[1] + '-' +
util.formatTime()[2], pageSize: 10, pageIndex: 1 }) }else{ }
this.getdataList(); },

技术
下载桌面版
GitHub
Gitee
SourceForge
百度网盘(提取码:draw)
云服务器优惠
华为云优惠券
腾讯云优惠券
阿里云优惠券
Vultr优惠券
站点信息
问题反馈
邮箱:[email protected]
吐槽一下
QQ群:766591547
关注微信