微信小程序日期选择器实例代码

<p style="text-align: center">


<div class="jb51code">
<pre class="brush:js;">
/ JS代码部分 /
3 const date = new Date()
const years = []
const months = []
const days = []
const hours = []
const minutes = []
var thisMon = date.getMonth();
var thisDay = date.getDate();
for (let i = 2017; i <= date.getFullYear() + 1; i++) {
years.push(i)
}
for (let i = date.getMonth(); i <= 11; i++) {
var k = i;
if (0 <= i && i < 9) {
k = "0" + (i + 1);
} else {
k = (i + 1);
}
months.push(k)
}
if (0 <= thisMon && thisMon < 9) {
thisMon = "0" + (thisMon + 1);
} else {
thisMon = (thisMon + 1);
}
if (0 <= thisDay && thisDay < 10) {
thisDay = "0" + thisDay;
}
var totalDay = mGetDate(date.getFullYear(),thisMon);
for (let i = 1; i <= 31; i++) {
var k = i;
if (0 <= i && i < 10) {
k = "0" + i
}
days.push(k)
}
for (let i = 0; i <= 23; i++) {
var k = i;
if (0 <= i && i < 10) {
k = "0" + i
}
hours.push(k)
}
for (let i = 0; i <= 59; i++) {
var k = i;
if (0 <= i && i < 10) {
k = "0" + i
}
minutes.push(k)
}
function mGetDate(year,month) {
var d = new Date(year,month,0);
return d.getDate();
}
Page({
data: {
years: years,year: date.getFullYear(),months: months,month: thisMon,days: days,day: thisDay,value: [1,thisMon - 1,thisDay - 1,0],hours: hours,hour: "00",minutes: minutes,minute: "00",},bindChange: function (e) {
const val = e.detail.value
this.setData({
year: this.data.years[val[0]],month: this.data.months[val[1]],day: this.data.days[val[2]],hour: this.data.hours[val[3]],minute: this.data.minutes[val[4]],})
var totalDay = mGetDate(this.data.year,this.data.month);
var changeDate = [];
for (let i = 1; i <= totalDay; i++) {
var k = i;
if (0 <= i && i < 10) {
k = "0" + i
}
changeDate.push(k)
}
this.setData({
days: changeDate
})
},})

/ css代码部分 /
.time-title{
float:left;
width:20%;
text-align:center;
color:#45BCE8;
}
.picker-text{
text-align:center;
}
/mask/
.time_screens {
width: 100%;
position: fixed;
bottom: 0;
left: 0;
z-index: 1000;
opacity: 0.5;
overflow: hidden;
}
/ HTML代码部分 /
<view class="time_screens">
<view style="text-align:center;color:#45BCE8">{{year}}-{{month}}-{{day}}
<label style="float:left;margin-left:30px;">取消
<label style="float:right;margin-right:30px;">确定

/* Json */ { "navigationBarTitleText": "XXXX" }

总结

以上所述是小编给大家介绍的微信小程序日期选择器实例代码。编程之家 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持

相关文章

1. 获取输入框数据wxml中的input上增加bindinput属性,和方法值在js部分定义与之对应的方法,只要在输入...
1.map组件的高度如果想要铺满屏幕,要是使用height:100vh样式2.获取位置要在app.json中标明权限3.先使用...
QQ小程序支付 Java后端 同学折腾QQ小程序的支付折腾了好几天,没有完成统一下单,因为我做过微信和支付...
前言: 在实际项目开发中我们经常会遇到账号统一的问题,如何在不同端或者是不同的登录方式下保证同一个...
一、前言: 我发现很多的同学都在抱怨说微信小程序的picker的mode = selector/mode = multiSelector 无...
前言: 之前自己做一个uni-app的项目的时候前端需要实现一个比较复杂的动态tab和swiper切换的功能,但是...