欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2018年12月28日 10:46:33   作者:Rattenking  
這篇文章主要為大家詳細(xì)介紹了微信小程序當(dāng)前時(shí)間時(shí)段選擇器插件使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

DEMO效果圖

插件思路

準(zhǔn)備工作

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

獲取時(shí)段

  1. 創(chuàng)建獲取當(dāng)天的時(shí)段函數(shù);
  2. 創(chuàng)建獲取本周的時(shí)段函數(shù);
  3. 創(chuàng)建獲取本月的時(shí)段函數(shù);
  4. 創(chuàng)建獲取本季度的時(shí)段函數(shù);
  5. 創(chuàng)建獲取本年的時(shí)段函數(shù);
  6. 創(chuàng)建自定義時(shí)段函數(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í)段函數(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();

項(xiàng)目地址

微信小程序—-時(shí)段選取插件

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 微信小程序?qū)崿F(xiàn)折疊展開效果

    微信小程序?qū)崿F(xiàn)折疊展開效果

    這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)折疊展開效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • uni-app動態(tài)修改導(dǎo)航欄標(biāo)題簡單步驟

    uni-app動態(tài)修改導(dǎo)航欄標(biāo)題簡單步驟

    uniapp作為一款開源軟件,可以做到一端多用,不過也有局限,在開發(fā)中有時(shí)候需要動態(tài)的去修改標(biāo)題,下面這篇文章主要給大家介紹了關(guān)于uni-app動態(tài)修改導(dǎo)航欄標(biāo)題的相關(guān)資料,需要的朋友可以參考下
    2023-06-06
  • js中substring和substr的定義和用法

    js中substring和substr的定義和用法

    這篇文章主要介紹了js中substring和substr的定義和用法,需要的朋友可以參考下
    2014-05-05
  • javascript 處理HTML元素必須避免使用的一種方法

    javascript 處理HTML元素必須避免使用的一種方法

    我們在編寫前臺頁面的時(shí)候,可能經(jīng)常會用到“javascript+數(shù)據(jù)”生成頁面元素的方法,但當(dāng)我們要處理的數(shù)據(jù)量較大,導(dǎo)致頁面需要展現(xiàn)過多的控件的時(shí)候,頁面的響應(yīng)速度也會直線下降
    2009-07-07
  • JS開發(fā)中基本數(shù)據(jù)類型具體有哪幾種

    JS開發(fā)中基本數(shù)據(jù)類型具體有哪幾種

    JS的數(shù)據(jù)類型包括基本數(shù)據(jù)類型、復(fù)雜數(shù)據(jù)類型和特殊數(shù)據(jù)類型,今天我們主要先講解一下基本數(shù)據(jù)類型。感興趣的朋友一起看看吧
    2017-10-10
  • uniapp中uni-popup的具體使用

    uniapp中uni-popup的具體使用

    本文主要介紹了uniapp中uni-popup的具體使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-06-06
  • 你知道JavaScript Symbol類型怎么用嗎

    你知道JavaScript Symbol類型怎么用嗎

    這篇文章主要介紹了你知道JavaScript Symbol類型怎么用嗎,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • JavaScript中的noscript元素屬性位置及作用介紹

    JavaScript中的noscript元素屬性位置及作用介紹

    Javascript插入到XHTML中要使用script元素,使用這個(gè)元素可以把Javascript嵌入到XHTML頁面中,讓腳本與標(biāo)記混合在一起,感興趣的朋友可以了解下
    2013-04-04
  • flash 得到自身url參數(shù)的代碼

    flash 得到自身url參數(shù)的代碼

    flash 得到自身url參數(shù)的代碼,需要的朋友可以參考下。
    2009-11-11
  • javascript動態(tài)獲取登錄時(shí)間和在線時(shí)長

    javascript動態(tài)獲取登錄時(shí)間和在線時(shí)長

    這篇文章主要為大家詳細(xì)介紹了javascript動態(tài)獲取登錄時(shí)間和在線時(shí)長的相關(guān)資料,獲得登錄時(shí)候的時(shí)間,用來和動態(tài)的時(shí)間做差來求時(shí)長,感興趣的小伙伴們可以參考一下
    2016-02-02

最新評論