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();
},