开始时间
<input type="text" id="statime" placeholder="Start date" value="">
结束时间
<input type="text" id="endtime" placeholder="End date" value="">
js
layui.use('laydate', function(){
var laydate = layui.laydate;
var nowTime = new Date().valueOf();
var max = null;
var start = laydate.render({
elem: '#statime',
type: 'date',
max: getstarttime(),
done: function(value, date) {
endMax = end.config.max;
end.config.min = date;
end.config.min.month = date.month - 1;
},
change: function(value, date, endDate) {
var timestamp2 = Date.parse(new Date(value));
timestamp2 = timestamp2 / 1000;
end.config.min = timestamp2;
end.config.min.month = date.month - 1;
}
});
var end = laydate.render({
elem: '#endtime',
type: 'date',
done: function(value, date) {
if ($.trim(value) == '') {
var curDate = new Date();
date = {
'date': curDate.getDate(),
'month': curDate.getMonth() + 1,
'year': curDate.getFullYear()
};
}
start.config.max = date;
start.config.max.month = date.month - 1;
}
});
});
function getstarttime() {
var date = new Date();
var seperator1 = "-";
var seperator2 = ":";
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 = date.getFullYear() + seperator1 + month +
seperator1 + strDate + " " + date.getHours() + seperator2 +
date.getMinutes() + seperator2 + date.getSeconds();
return currentdate;
}