weui.js之datepicker年月日时分秒的选择

weui.js之datepicker年月日时分秒的选择

<html>
	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.0.1/weui.min.css">
		<script type="text/javascript" src="https://res.wx.qq.com/t/wx_fed/cdn_libs/res/weui/1.2.3/weui.min.js"></script>
	</head>
<body>

	<script type="text/javascript">
 //    weui.alert('alert');
 //    // 示例2:
	// weui.datePicker({
	//      start: 1997, // 从今天开始
	//      end: new Date(),
	//      defaultValue: [2020, 6, 9],
	//      onChange: function(result){
	//          console.log(result);
	//      },
	//      onConfirm: function(result){
	//          console.log(result);
	//      },
	//      id: 'datePicker'
	// });

function isWhichTime() {
    let years = [];
    let mouth =[];
    let date = [];
    let hours = [];
    let minite = [];
    let seconds = [];
    if(!years.length&&!mouth.length) {
        for(let i = 1889; i <= 2030; i++) {
            years.push({
                label: i +"年" ,
                 value: i
               });
       }
    }
    if (!mouth.length) {
        mouth = costomDatePicker(mouth,1,13,"月" )
    }
    if(!date.length) {
        date = costomDatePicker(date,1,32,"日" )
    }
    if(!hours.length) {
        hours=costomDatePicker(hours,0,24,"时")
    }
    if(!minite.length) {
        minite=costomDatePicker(minite,0,60,"分")
    }
    if(!seconds.length) {
        seconds=costomDatePicker(seconds,0,60,"秒")
    }
 
    weui.picker(years,mouth,date,hours,minite,seconds,{
        //end:2030,
        id: new Date(),//让每一个点击弹框得都有一个不一样得id,这样就避免了共用一个弹框得时候,打开得日期是上一次另外一个得日期回显
        defaultValue: [new Date().getFullYear(), new Date().getMonth()+1, new Date().getDate(),new Date().getHours(),new Date().getMinutes(),new Date().getSeconds()],
        onConfirm: result=> {
            //result 是数组,返回得是当前选中得数,如[{lable:'2019年,value:2019},{lable:'2月,value:2},{lable:'2号,value:2}]
            if (result.length){
                //yyyy-mm-dd hh:mm:ss
                let time=result[0].value+'-'+result[1].value+'-'+result[2].value+' '+result[3].value+':'+result[4].value+':'+result[5].value;
                console.log('time',time)
                this.el.find(timeSelector).val(time);
           }
        }
    });
}

//自定义日期:月时分秒
function costomDatePicker(years,startTime,endTime,str){
    for(let j = startTime; j < endTime; j++) {
       years.push({
            label: ('' + j).length === 1 ? '0'+j + str : '' + j + str,
            value: ('' + j).length === 1 ? '0'+j : '' + j ,
        });
    }
    return years;
};

isWhichTime();




</script>
	
</body>


</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WMSmile

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值