laydate.render设置结束时间大于开始时间,且两者时间相差不超过3天

/时间控件设置/
if ($(".select-time").length > 0) {
layui.use(‘laydate’, function() {
var laydate = layui.laydate;
var startType = $(’#startTime’).attr(“data-type”) || ‘date’;
var endType = $(’#endTime’).attr(“data-type”) || ‘date’;
var startDate = laydate.render({
elem: ‘#startTime’,
type: startType,
max: $(’#endTime’).val(),
theme: ‘molv’,
trigger: ‘click’,
done: function(value, date) {
// 结束时间大于开始时间
if (value !== ‘’) {
endDate.config.min.year = date.year;
endDate.config.min.month = date.month - 1;
endDate.config.min.date = date.date;
endDate.config.min.hours = date.hours;
endDate.config.min.minutes = date.minutes;
endDate.config.min.seconds = date.seconds;
/设置两者时间不超过三天/
var now = new Date();
// return now.getFullYear() + “-” + (now.getMonth() + 1) + “-” + now.getDate();
var timeMax = date.year + “-” + date.month + “-” + date.date+" “+date.hours+”:"+date.minutes+":"+date.seconds;
timeMax = new Date(timeMax);
timeMax.setDate(timeMax.getDate() + 3);
if(now.getTime() > timeMax.getTime()){
endDate.config.max.year = timeMax.getFullYear();
endDate.config.max.month = timeMax.getMonth();
endDate.config.max.date = timeMax.getDate();
endDate.config.max.hours =timeMax.getHours();
endDate.config.max.minutes = timeMax.getMinutes();
endDate.config.max.seconds = timeMax.getSeconds();
}
} else {
endDate.config.min.year = ‘’;
endDate.config.min.month = ‘’;
endDate.config.min.date = ‘’;
}
}
});
var endDate = laydate.render({
elem: ‘#endTime’,
max: maxDate(),
theme: ‘molv’,
trigger: ‘click’,
type: endType,
done: function(value, date) {
// 开始时间小于结束时间
console.log(“oop”+value)
if (value !== ‘’) {
startDate.config.max.year = date.year;
startDate.config.max.month = date.month - 1;
startDate.config.max.date = date.date;
startDate.config.max.hours = date.hours;
startDate.config.max.minutes = date.minutes;
startDate.config.max.seconds = date.seconds;
/设置两者时间不超过三天/
startDate.config.min.year = date.year;
startDate.config.min.month = date.month - 1;
startDate.config.min.date = date.date-3;
startDate.config.min.hours = date.hours;
startDate.config.min.minutes = date.minutes;
startDate.config.min.seconds = date.seconds;
} else {
startDate.config.max.year = ‘2099’;
startDate.config.max.month = ‘12’;
startDate.config.max.date = ‘31’;
}
}
});
});
}
function maxDate() {
// var now = new Date();
// return now.getFullYear() + “-” + (now.getMonth() + 1) + “-” + now.getDate();
var currentDate = new Date(+new Date()+836001000).toISOString().replace(/T/g,’ ‘).replace(/.[\d]{3}Z/,’’);
return currentDate;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

辉耀soul

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

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

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

打赏作者

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

抵扣说明:

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

余额充值