使用layui的插件laydate时候,可能会遇到这样的场景:查询某一天内的数据,因此,希望开始时间是某天的0时0分0秒,结束时间则是某天的23时59分59秒,例如,开始时间如: 2018-07-26 00:00:00,结束时间格式如:2018-07-26 23:59:59。
这个时候怎么来设置laydate插件呢?可以通过ready或者done方法中设置this.dateTime这个属性中时分秒来解决这个问题。
代码如下(附部分时间范围控制代码,可忽略):
var endTime = laydate.render({
elem: '#_endtime',
type: 'datetime',
format: 'yyyy-MM-dd HH:mm:ss',
theme: 'molv',
ready: function(date){
this.dateTime.hours=23;
this.dateTime.minutes=59;
this.dateTime.seconds=59;
},
done: function(value, date, endDate){
if(value){
beginTime.config.max = {
year:date.year,
month:date.month-1,
date: date.date,
hours:date.hours>0?date.hours:23,
minutes:date.minutes>0?date.minutes:59,
seconds:date.seconds>0?date.seconds:59
};
}else{
beginTime.config.max = {
year:2099,
month:11,
date: 31,
hours:0,
minutes:0,
seconds:0
};
}
}
});