【layui】layui时间插件自定义代码

        <div class="layui-form-item" style="padding-top: 50px;">
			<div class="layui-inline">
				<label class="layui-form-label">日期范围</label>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" id="test1" placeholder=" 到 ">
				</div>
				<button class="layui-btn layui-btn-normal">查询</button>
			</div>
		</div>
//执行一个laydate实例
        laydate.render({
            elem: '#test1' //指定元素
            ,max: getNowFormatDate()
            ,range: '到'
            ,format: 'yyyy-MM-dd'
        });

        //获取当前时间,格式YYYY-MM-DD
        function getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = year + seperator1 + month + seperator1 + strDate;
            return currentdate;
        }

逻辑层取出范围日期代码 

String starDay = "";
        String endDay = "";
        String  dateRange = ("" + pd.get("dateRange")).replaceAll("\\s*", "");//dateRange=2018-03-15 到 2018-03-22
        if(dateRange != null && !"".equals(dateRange) && !"null".equals(dateRange)) {
            int index = dateRange.indexOf("到");
            if(index > 0) {
                starDay = dateRange.substring(0, index);
                endDay = dateRange.substring(index + 1, dateRange.length());
            }
        }

猜你喜欢

转载自blog.csdn.net/wjx_jasin/article/details/82981667