时间:2021-05-18
微信小程序时间选择插件-弹出选择,供大家参考,具体内容如下
wxml
<modal class="modal" hidden="{{flag}}" no-cancel bindconfirm="getTime" confirmText="确定"> <view class="modal-content"><view class="time_screens" > <view style="text-align:center;color:#45BCE8">{{year}}-{{month}}-{{day}} {{hour}}:{{minute}}</view> <view style="border-top:1px solid #45BCE8;height:25px;font-size:14px;"> <view class="time-title">年</view> <view class="time-title">月</view> <view class="time-title">日</view> <view class="time-title">时</view> <view class="time-title">分</view> </view> <picker-view indicator-style="height: 50px;" style="width: 100%; height: 300px;" value="{{value}}" bindchange="bindChange"> <picker-view-column class="picker-text"> <view wx:for="{{years}}" style="line-height: 50px">{{item}}</view> </picker-view-column> <picker-view-column class="picker-text"> <view wx:for="{{months}}" style="line-height: 50px">{{item}}</view> </picker-view-column> <picker-view-column class="picker-text"> <view wx:for="{{days}}" style="line-height: 50px">{{item}}</view> </picker-view-column> <picker-view-column class="picker-text"> <view wx:for="{{hours}}" style="line-height: 50px">{{item}}</view> </picker-view-column> <picker-view-column class="picker-text"> <view wx:for="{{minutes}}" style="line-height: 50px">{{item}}</view> </picker-view-column> </picker-view></view> </view></modal >js:
const date = new Date()const years = []const months = []const days = []const hours = []const minutes = []var thisMon = date.getMonth();var thisDay = date.getDate();var thisHours = date.getHours();var thisMinutes = date.getMinutes();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();} var app = getApp();var api = app.globalData.api;Page({ /** * 页面的初始数据 */ data: { checkTime: date.getFullYear() + "-" + thisMon + "-" + thisDay + " " + thisHours + ":" + thisMinutes, //---时间控件参数 flag: true, years: years, year: date.getFullYear(), months: months, month: thisMon, days: days, day: thisDay, value: [1, thisMon - 1, thisDay - 1, 0, 0], hours: hours, hour: thisHours, minutes: minutes, minute: thisMinutes, }, showModel: function (e) { this.setData({ flag: false }); }, getTime: function (e) { var times = this.data.year + "-" + this.data.month + "-" + this.data.day + " " + this.data.hour + ":" + this.data.minute this.setData({ flag: true, checkTime: times }); }, 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:
.kouviewList{ background-color: #F7F7F7;}.kouview{ height:170px; margin-top:5px; }.kouviews{ height:150px; margin-top:5px; }.time-title{ float:left;width:20%;text-align:center;color:#45BCE8}.picker-text{ text-align:center;}以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
微信小程序滚动选择器(时间日期)详解微信小程序自己封装了很多控件,用起来确实很方便,如果这是Android里面,还需要自己去定义,不废话,效果图:一起来看看怎么
企业微信小程序的开发通过企业微信小程序模拟器插件来实现,方便用户在微信开发者工具中进行企业微信小程序开发、调试和代码上传。一、开发须知开发者在使用企业微信小程序
微信小程序时间格式化微信小程序虽然还在内测,但是已经火的不行.赶紧看看.记录学习路上的点点滴滴.获取时间直接用Date.now()得到一串数字.如下图:获取格式
微信公众平台很早之前就上线了小程序插件的功能,开发者可以直接在在小程序的内部提供插件为用户进行服务。那么,还是有很多开发者不知道微信小程序如何使用插件,下面小编
微信小程序选择器(时间,日期,地区)微信小程序开发由于本人最近学习微信小程序的开发,根据自己的实践结果整理了下结果,对日期选择器,时间选择器,地区选择器做的实例