比较日期大小的两种方式

1.

$.extend($.fn.validatebox.defaults.rules, { 
sTEDate : {/* 验证开始日期是否小于结束日期 ,应用于结束时间标签*/
validator : function(value, param) {
if (value == undefined || value == "") {
return true;
}
if (param == undefined || param.length == 0) {
return false;
}
var sDate = new Date($(param[0]).datebox('getValue'))
.getTime();
var eDate = new Date(value).getTime();
return eDate >= sDate;
},
message : '结束日期必须大于等于开始日期!'
},  
mToDate : {/* 验证开始日期是否大于当天日期 */
validator : function(value,param) {
if (value == undefined || value == "") {
return true;
}
if (param == undefined || param.length == 0) {
return false;
}
var sDate = new Date(date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()).getTime();
var toDate = new Date(value).getTime();
return toDate>=sDate;
},
message : '开始日期必须大于等于当前日期!'
}, 
});

2.

 $("#beginDate").datebox({
    onSelect:function(record){
    if(record != undefined){
    var start=DateUtil.strToDate(date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate());
var endStart=DateUtil.strToDate($("#beginDate").datebox('getValue'));
if(DateUtil.dateDiff("d",start,endStart)<0){
$.messager.alert('提示','开始日期不能小于制单日期.');
$("#beginDate").datebox('setValue','');
}
    }
        }
    });*/
   /* $("#endDate").datebox({
    onSelect:function(record){
if(record != undefined){
var start=DateUtil.strToDate($("#beginDate").datebox('getValue'));
var endStart=DateUtil.strToDate($("#endDate").datebox('getValue'));
if(DateUtil.dateDiff("d",start,endStart)<0){
$("#endDate").datebox('setValue','');
$.messager.alert('提示','结束日期不能小于开始日期.');
}
}
}
    });

 this.dateDiff = function(strInterval, dtStart, dtEnd) {  
        switch (strInterval) {  
            case 's' :return parseInt((dtEnd - dtStart) / 1000); 
            case 'n' :return parseInt((dtEnd - dtStart) / 60000); 
            case 'h' :return parseInt((dtEnd - dtStart) / 3600000); 
            case 'd' :return parseInt((dtEnd - dtStart) / 86400000); 
            case 'w' :return parseInt((dtEnd - dtStart) / (86400000 * 7)); 
            case 'm' :return (dtEnd.getMonth()+1)+((dtEnd.getFullYear()-dtStart.getFullYear())*12) - (dtStart.getMonth()+1); 
            case 'y' :return dtEnd.getFullYear() - dtStart.getFullYear(); 
        } 
    }
 
    /**
    * 字符串转换为日期对象
    * @param date Date 格式为yyyy-MM-dd HH:mm:ss,必须按年月日时分秒的顺序,中间分隔符不限制
    */
    this.strToDate = function(dateStr){
        var data = dateStr; 
        var reCat = /(\d{1,4})/gm;  
        var t = data.match(reCat);
        t[1] = t[1] - 1;
        eval('var d = new Date('+t.join(',')+');');
        return d;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值