//选择日期
function change(obj){ var timeOne = $("#choose_one").val(); var timeTwo = $("#choose_two").val(); //获取当前时间 var newdate= CurentTime(); if(CompareDate(timeOne,timeTwo)){ layer.alert("开始时间不能大于结束时间"); $(obj).val(""); return false; } if(CompareDate(timeOne,newdate)){ layer.alert("开始时间不能大于当前时间"); $(obj).val(""); return false; } if(CompareDate(timeTwo,newdate)){ layer.alert("结束时间不能大于当前时间"); $(obj).val(""); return false; } };
function CompareDate(d1,d2){ return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/")))); }
function CurentTime(){ var now = new Date(); var year = now.getFullYear(); //年 var month = now.getMonth() + 1; //月 var day = now.getDate(); //日 var hh = now.getHours(); //时 var mm = now.getMinutes(); //分 var clock = year + "-"; if(month < 10) clock += "0"; clock += month + "-"; if(day < 10) clock += "0"; clock += day + " "; if(hh < 10) clock += "0"; clock += hh + ":"; if (mm < 10) clock += '0'; clock += mm; return(clock); }
两个时间比较大小,结束日期不能大于起始日期,起始日期不能大于当前日期
最新推荐文章于 2023-05-10 14:25:18 发布