Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use WeChat Mini Programs's current time period Selector plug-in

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "how to use WeChat Mini Programs's current time selector plug-in". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!

DEMO effect diagram

Plug-in idea

Preparatory work

Get the current time and the current year, month, day and day of the week

Create a function that processes date numbers

Create a function to format a date

Create a function that gets the number of days in a month

Create a month function that gets the start of the quarter.

Get period of time

Create a time period function to get the current day

Create a function to get the time period of the week

Create a time period function to get this month

Create a period function to get the current quarter

Create a time period function to get this year

Create a custom period function.

JS in the preparation phase

Constructor () {this.now = new Date (); this.nowYear = this.now.getYear (); / / current year this.nowMonth = this.now.getMonth (); / / current month this.nowDay = this.now.getDate (); / / current day this.nowDayOfWeek = this.now.getDay (); / / what day of the week is today 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;}

Period function JS

/ / get today's date getNowDate () {return this.formatDate (new Date (this.nowYear, this.nowMonth, this.nowDay));} / / get this week's start date getWeekStartDate () {return this.formatDate (new Date (this.nowYear, this.nowMonth, this.nowDay-this.nowDayOfWeek + 1)) } / / get the end date of this week getWeekEndDate () {return this.formatDate (new Date (this.nowYear, this.nowMonth, this.nowDay + (6-this.nowDayOfWeek + 1));} / / get the start date of this month getMonthStartDate () {return this.formatDate (this.nowYear, this.nowMonth, 1)) } / / get the end date of the month getMonthEndDate () {return this.formatDate (new Date (this.nowYear, this.nowMonth, this.getMonthDays (this.nowMonth);} / / get the start date of the current quarter getQuarterStartDate () {return this.formatDate (this.nowYear, this.getQuarterStartMonth (), 1)) } / / get the end date of the current quarter getQuarterEndDate () {return this.formatDate (new Date (this.nowYear, this.getQuarterStartMonth () + 2, this.getMonthDays (this.getQuarterStartMonth () + 2);} / / get the start date of the year getYearStartDate () {return this.formatDate (this.nowYear (this.nowYear, 0,1));} / / get the end date of the year getYearEndDate () {return this.formatDate (new Date (this.nowYear, 11,31);}

Usage

1. Introduction of getperiod.js

Const GetPeriod = require (".. /.. / utils/getperiod.js")

two。 Use getperiod.js

This.time = new GetPeriod (); / / get the end date of the year let end = this.time.getYearEndDate ()

Project address

WeChat Mini Programs-time period selection plug-in

This is the end of git clone git@github.com:Rattenking/GetPeriod.git 's "how to use the WeChat Mini Programs current time Selector plug-in". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report