微信小程序当前时间时段选择器插件如何用
发表于:2024-10-19 作者:千家信息网编辑
千家信息网最后更新 2024年10月19日,本篇内容介绍了"微信小程序当前时间时段选择器插件如何用"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
千家信息网最后更新 2024年10月19日微信小程序当前时间时段选择器插件如何用
本篇内容介绍了"微信小程序当前时间时段选择器插件如何用"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
DEMO效果图
插件思路
准备工作
获取当前时间,同时获取当前的年、月、日、周几;
创建处理日期数字的函数;
创建格式化日期的函数;
创建获取某月天数的函数;
创建获取季度开始的月份函数。
获取时段
创建获取当天的时段函数;
创建获取本周的时段函数;
创建获取本月的时段函数;
创建获取本季度的时段函数;
创建获取本年的时段函数;
创建自定义时段函数。
准备阶段的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
"微信小程序当前时间时段选择器插件如何用"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
日期
时段
函数
季度
插件
时间
程序
格式
选择
内容
天数
数字
更多
月份
知识
准备
实用
学有所成
接下来
使用方法
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
浅谈三大中文数据库
电子商务网络安全性
软件开发工程造价培训
梦幻新诛仙7.8服务器
软件开发利用原型模型
军人手机网络安全图片
app打车软件开发费用
中免日上服务器
网络安全工程师相关政策
网络安全技术用于网络攻击
海南质量软件开发价格表格
手机网络安全的方法
软件开发大学考本
上海运维管理软件开发报价
金融科技互联网物流
新乐软件开发者
战地4国内服务器
厦门硅谷软件开发
vfp数据库应用软件开发
无线网络安全认证厂商
用友u8服务器配置
成都网络技术培训公司
黑莓9550软件开发
服务器怎么加回程路由
镇江专业软件开发行业
为什么服务器会发生错误
女孩适合软件开发吗
师生网络安全意识
伊宁互联网科技价格
厦门硅谷软件开发