国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序當(dāng)前時間時段選擇器插件使用方法詳解

2024-07-22 01:19:19
字體:
供稿:網(wǎng)友

本文實例為大家分享了微信小程序當(dāng)前時間時段選擇器的實現(xiàn)代碼,供大家參考,具體內(nèi)容如下

DEMO效果圖

插件思路

準(zhǔn)備工作

    獲取當(dāng)前時間,同時獲取當(dāng)前的年、月、日、周幾; 創(chuàng)建處理日期數(shù)字的函數(shù); 創(chuàng)建格式化日期的函數(shù); 創(chuàng)建獲取某月天數(shù)的函數(shù); 創(chuàng)建獲取季度開始的月份函數(shù)。

獲取時段

    創(chuàng)建獲取當(dāng)天的時段函數(shù); 創(chuàng)建獲取本周的時段函數(shù); 創(chuàng)建獲取本月的時段函數(shù); 創(chuàng)建獲取本季度的時段函數(shù); 創(chuàng)建獲取本年的時段函數(shù); 創(chuàng)建自定義時段函數(shù)。

準(zhǔn)備階段的JS

constructor() { this.now = new Date(); this.nowYear = this.now.getYear(); //當(dāng)前年  this.nowMonth = this.now.getMonth(); //當(dāng)前月  this.nowDay = this.now.getDate(); //當(dāng)前日  this.nowDayOfWeek = this.now.getDay(); //今天是本周的第幾天  this.nowYear += (this.nowYear < 2000) ? 1900 : 0;}//格式化數(shù)字formatNumber(n) { n = n.toString() return n[1] ? n : '0' + n}//格式化日期formatDate(date) { let myyear = date.getFullYear(); let mymonth = date.getMonth() + 1; let myweekday = date.getDate(); return [myyear, mymonth, myweekday].map(this.formatNumber).join('-');}//獲取某月的天數(shù)getMonthDays(myMonth) { let monthStartDate = new Date(this.nowYear, myMonth, 1); let monthEndDate = new Date(this.nowYear, myMonth + 1, 1); let days = (monthEndDate - monthStartDate) / (1000 * 60 * 60 * 24); return days;}//獲取本季度的開始月份getQuarterStartMonth() { let startMonth = 0; if (this.nowMonth < 3) {  startMonth = 0; } if (2 < this.nowMonth && this.nowMonth < 6) {  startMonth = 3; } if (5 < this.nowMonth && this.nowMonth < 9) {  startMonth = 6; } if (this.nowMonth > 8) {  startMonth = 9; } return startMonth;}

時段函數(shù)JS

//獲取今天的日期 getNowDate() { return this.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay)); } //獲取本周的開始日期 getWeekStartDate() { return this.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek + 1)); } //獲取本周的結(jié)束日期 getWeekEndDate() { return this.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay + (6 - this.nowDayOfWeek + 1))); } //獲取本月的開始日期 getMonthStartDate() { return this.formatDate(new Date(this.nowYear, this.nowMonth, 1)); } //獲取本月的結(jié)束日期 getMonthEndDate() { return this.formatDate(new Date(this.nowYear, this.nowMonth, this.getMonthDays(this.nowMonth))); } //獲取本季度的開始日期 getQuarterStartDate() { return this.formatDate(new Date(this.nowYear, this.getQuarterStartMonth(), 1)); } //獲取本季度的結(jié)束日期  getQuarterEndDate() { return this.formatDate(new Date(this.nowYear, this.getQuarterStartMonth() + 2, this.getMonthDays(this.getQuarterStartMonth() + 2))); } //獲取本年的開始日期 getYearStartDate() { return this.formatDate(new Date(this.nowYear, 0, 1)); } //獲取本年的結(jié)束日期 getYearEndDate() { return this.formatDate(new Date(this.nowYear, 11, 31)); }            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 特克斯县| 大城县| 新建县| 阳江市| 高唐县| 英吉沙县| 宣恩县| 安丘市| 临城县| 咸阳市| 始兴县| 北辰区| 沾化县| 石家庄市| 金乡县| 礼泉县| 苍溪县| 太白县| 托克逊县| 磴口县| 文登市| 江阴市| 颍上县| 临江市| 凌源市| 高阳县| 丘北县| 璧山县| 高尔夫| 博兴县| 镇原县| 宿迁市| 广南县| 邯郸市| 象州县| 尚志市| 格尔木市| 长宁区| 罗田县| 公安县| 哈尔滨市|