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

首頁 > 課堂 > 小程序 > 正文

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

2020-03-21 16:04:00
字體:
來源:轉載
供稿:網友

本文實例為大家分享了微信小程序當前時間時段選擇器的實現代碼,供大家參考,具體內容如下

DEMO效果圖

微信小程序,時間選擇器

插件思路

準備工作

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

獲取時段

  1. 創建獲取當天的時段函數;
  2. 創建獲取本周的時段函數;
  3. 創建獲取本月的時段函數;
  4. 創建獲取本季度的時段函數;
  5. 創建獲取本年的時段函數;
  6. 創建自定義時段函數。

準備階段的JS

constructor() { this.now = new Date(); this.nowYear = this.now.getYear(); //當前年  this.nowMonth = this.now.getMonth(); //當前月  this.nowDay = this.now.getDate(); //當前日  this.nowDayOfWeek = this.now.getDay(); //今天是本周的第幾天  this.nowYear += (this.nowYear < 2000) ? 1900 : 0;}//格式化數字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('-');}//獲取某月的天數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;}

時段函數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)); } //獲取本周的結束日期 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)); } //獲取本月的結束日期 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)); } //獲取本季度的結束日期  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)); } //獲取本年的結束日期 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();//獲取本年的結束日期let end = this.time.getYearEndDate();

項目地址

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

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 北辰区| 分宜县| 红安县| 佛学| 甘德县| 望谟县| 息烽县| 普定县| 浦北县| 平湖市| 陕西省| 林芝县| 白城市| 太仆寺旗| 桃源县| 凤凰县| 武城县| 黄山市| 米脂县| 龙岩市| 历史| 云和县| 正镶白旗| 南漳县| 吐鲁番市| 泸溪县| 平江县| 乌鲁木齐县| 石泉县| 志丹县| 望谟县| 太湖县| 长子县| 乳源| 山东| 桐柏县| 监利县| 兰坪| 定州市| 垣曲县| 西丰县|