js 时间处理函数 获取今天的前几天和后几天的任意一天

 
var now = new Date();
let today = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate();//2018-3-27
var nowDayOfWeek = now.getDay();
console.log(nowDayOfWeek )
dateObject.getDay()
返回值
dateObject 所指的星期中的某一天,使用本地时间。返回值是 0(周日) 到 6(周六) 之间的一个整数。
 
 
that.getWeek(0)   //今天
 
//----------------------------------------------------------------------------------------------
onLoad() {
let _this = this;
let spjlNo = this.data.spjlNo;
let that = this;
let user = wx.getStorageSync('user');
promiseHandle(wx.getSystemInfo).then((data) => {
_this.setData({
updatePanelTop: data.windowHeight
});
});
changeDate.call(this);
let date = new Date();
let todaytime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
this.setData({
todaytime: todaytime,
cheToday: todaytime,
dayIndex:date.getDate()
})

// 服药记录
that.sleepRq(todaytime);
that.foodRq(todaytime);
let now = new Date();
 
let today = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate();
let nowDayOfWeek = now.getDay();
console.log(today)
this.selectFn(nowDayOfWeek, today)
},
selectFn: function (n, toady) {
let that=this;
let weekdays = this.data.weekdays;
if (n != 0) {
weekdays[n - 1] = toady;
} else {
weekdays[weekdays.length - 1] = toady
}
// console.log(weekdays)
// console.log(n)
for (let i = 0; i < weekdays.length; i++) {
if (weekdays[i] == '') {
// console.log(i)
if (i > n - 1) {
weekdays[i] = this.getWeek(i - (n-1)+1 )
} else {
weekdays[i] = this.getWeek(i-(n-1)+1 )
}
}
if (i >= weekdays.length - 1) {
setTimeout(function () {
 
that.chuLiday(weekdays);
}, 300);

}
}
},
chuLiday: function (weekdays){
let that=this;
// var arr = str.split(",");
for (let key in weekdays ){
weekdays[key] = weekdays[key].split("-");
}
// console.log(weekdays)
that.setData({
weekdays: weekdays
})

},

getWeek: function (i) {
var now = new Date();

var firstDay = new Date(now - (now.getDay() - 2) * 86400000);
firstDay.setDate(firstDay.getDate() + i);
let mon = Number(firstDay.getMonth()) + 1;
return now.getFullYear() + "-" + mon + "-" + firstDay.getDate();
},
 

转载于:https://www.cnblogs.com/dianzan/p/8658080.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值