这篇文章主要介绍了微信小程序一周时间表功能实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
页面结构
view class=' DateView ' image class=' DateLeft ' bind tap=' previweek ' src=' http :/./RES/imgs/DateLeft。png‘/图像视图{{dateStart}}至{ { DateEnd } }/view image class=' DateRight ' bind tap=' NextWeek ' src=' http :/./RES/imgs/DateRight。png '/image/viewxss。dateView { padd :0 32 rpxhway :98 rpxdisplay : flex align-items :居中;背景# fff}。dateViewimage { width :50 rpx heart :50 rpx }。dateview视图{ flex : 1;文本对齐:中心;color : # 333 font-size : 34 rpx;}js
const GetPeriod=require('././utils/get句点。js’);页面({ /** *页面的初始数据*/data : { current ttab : 1,dateStart:'2019-10-16 ',dateEnd: '2019-10-16 ',},/** *生命周期函数-监听页面加载*/onLoad:函数(选项){让那个=这个;that.getWeekStartDate(0) },//获取本周的开始日期getWeekStartDate(NumDay){ 0让那个=这个;这个. now=新日期();这个。现在年份=这个。现在。getyear();//当前年这个。现在月份=这个。现在。getmonth();//当前月这个。现在天=这个。现在。getdate();//当前日这个。nowdayofweek=这个。现在。getday();//今天是本周的第几天今年=2000年?1900 : 0;让dateStart=GetPeriod.formatDate(新日期(今年,今年,这个月,这个。这一天。now day fweek 1 NumDay));让dateEnd=GetPeriod.formatDate(新日期(今年,今年,这个月,这个。这一天。现在是第7周第7天(NumDay));//console.log(dateStart) //获取今天日期让now=GetPeriod.formatDate(新日期(今年,今年,这个月,这个。now day));现在=现在。替换(///g,'/');现在=现在。子串(5);这个。setdata({日期开始:日期开始,日期结束:日期结束,现在:现在:}) //初始化数据(历史纪录)变量时间戳=日期。解析(新日期(这个。数据。开始日期));时间戳=时间戳/1000;//console.log(时间戳);那个。setdata({ timestamp : timestamp })},//点击上一周前一周:函数{这个。数据。num=这个。数据。num-7;这个。getweekstartdate(这。数据。num);},//点击下一周下周:函数{这个。数据。num=这个。数据。num 7;这个。getweekstartdate(这。数据。num);},})函数构造函数1(){ this。now=新日期();这个。现在年份=这个。现在。getyear();//当前年这个。现在月份=这个。现在。getmonth();//当前月这个。现在天=这个。现在。getdate();//当前日这个。nowdayofweek=这个。现在。getday();//今天是本周的第几天今年=2000年?1900 : 0;}//格式化数字函数formatNumber (n) { n=n.toString()返回n[1]?n : '0' n}//格式化日期函数格式日期(日期){ 0让我的年份=日期。getfull year();让我的月份=日期。get month()1;让我的工作日=日期。getdate();返回[我的年份,我的月份,我的工作日]。map(this.formatNumber).join('-');}//获取某月的天数函数getMonthDays (myMonth)让月份开始日期=新日期(这。现在年,我的月,1);让每月日期=新日期(this.nowYear,myMonth 1,1);让天数=(monthenddeat-months startdate)/(1000 * 60 * 60 * 24);返程天数;}//获取本季度的开始月份函数getquartstartmonth(){ 0让start month=0;如果(这个。现在第3个月){开始月份=0;}如果(2这。这个月。现在第6个月){开始月份=3;}如果(5这个。这个月。现在第9个月){开始月份=6;}如果(这个。现在第8个月){开始月份=9;}返回startMonth}//获取本周的开始日期函数getWeekStartDate(){ 0返回this.formatDate(新日期(今年,今年,这个月,这个。这一天。now day fweek 1));}//获取本周的结束日期函数getWeekEndDate(){ 0返回this.formatDate(新日期(今年,今年,这个月,这个。现在第6天。now day fweek 1)));}//获取今天的日期函数getNowDate(){ 0返回this.formatDate(新日期(今年,今年,这个月,这个。now day));}函数格式化时间(日期){ var year=date。getfullyear()var month=date。getmonth()1 var day=date。getdate()var hour=date。gethours()var分钟=日期。getminutes()var second=date。getseconds()返回[年、月、日]。地图(格式号)。联接('/')' '[小时、分钟、秒]。地图(格式号)。加入(' : ')模块。exports={ format number : format number,constructor1: constructor1,formatDate: formatDate,getMonthDays: getMonthDays,getquartastarmonth 3360 getquartastarmonth,getWeekStartDate : getnow date,getWeekEndDate,formatTime: formatTime}效果如下
以上就是本文的全部内容。希望对大家的学习有帮助,支持我们。