微信小程序當(dāng)前時間時段選擇器插件怎么用-創(chuàng)新互聯(lián)

這篇文章給大家分享的是有關(guān)微信小程序當(dāng)前時間時段選擇器插件怎么用的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),呼瑪企業(yè)網(wǎng)站建設(shè),呼瑪品牌網(wǎng)站建設(shè),網(wǎng)站定制,呼瑪網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,呼瑪網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。

具體內(nèi)容如下

DEMO效果圖

微信小程序當(dāng)前時間時段選擇器插件怎么用

插件思路

準(zhǔn)備工作

  1. 獲取當(dāng)前時間,同時獲取當(dāng)前的年、月、日、周幾;

  2. 創(chuàng)建處理日期數(shù)字的函數(shù);

  3. 創(chuàng)建格式化日期的函數(shù);

  4. 創(chuàng)建獲取某月天數(shù)的函數(shù);

  5. 創(chuàng)建獲取季度開始的月份函數(shù)。

獲取時段

  1. 創(chuàng)建獲取當(dāng)天的時段函數(shù);

  2. 創(chuàng)建獲取本周的時段函數(shù);

  3. 創(chuàng)建獲取本月的時段函數(shù);

  4. 創(chuàng)建獲取本季度的時段函數(shù);

  5. 創(chuàng)建獲取本年的時段函數(shù);

  6. 創(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));
 }

使用方法

1.引入getperiod.js

const GetPeriod = require("../../utils/getperiod.js");

2.使用getperiod.js

this.time = new GetPeriod();

//獲取本年的結(jié)束日期
let end = this.time.getYearEndDate();

項目地址

微信小程序—-時段選取插件

git clone git@github.com:Rattenking/GetPeriod.git

感謝各位的閱讀!關(guān)于“微信小程序當(dāng)前時間時段選擇器插件怎么用”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

當(dāng)前題目:微信小程序當(dāng)前時間時段選擇器插件怎么用-創(chuàng)新互聯(lián)
URL地址:http://muchs.cn/article22/dcpdjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、企業(yè)建站網(wǎng)站改版、軟件開發(fā)做網(wǎng)站、服務(wù)器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計