• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

js 小程序获取本周七天

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
data: {
weekdays:[\'\',\'\',\'\',\'\',\'\',\'\',\'\']
},
 
 
onLoad: function (options) {
let that = this;
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 weekdays = this.data.weekdays;
if(n!=0){
weekdays[n - 1] = toady;
}else{
weekdays[weekdays.length - 1] = toady
}
console.log(weekdays)
// console.log(this.getWeek(0))
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)
}else{
weekdays[i] = this.getWeek(i - n + 1)
}
}
if (i >= weekdays.length-1){
console.log(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();
},
 
["2018-3-26", "2018-3-27", "2018-3-28", "2018-3-29", "2018-3-30", "2018-3-31", "2018-4-1"]

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
小程序 之安全问题考虑发布时间:2022-07-18
下一篇:
小程序采坑记(四) picker组件发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap