日期:2014-05-16  浏览次数:20359 次

js 验证日期

function checkDate(date1,date2){
var jsdate1 = $('#'+date1);
var jsdate2 = $('#'+date2);
var dateObj = new Date();
var dateYear = dateObj.getYear();
var dateMonth = dateObj.getMonth() + 1;
var dateDay = dateObj.getDate();
var date = dateYear + "-" + dateMonth + "-" + dateDay;
date1 = jsdate1.val().replace(/\-/gi,"/");
date2 = jsdate2.val().replace(/\-/gi,"/");
date = date.replace(/\-/gi,"/");
var flag = 0;
var time1 = new Date(date1).getTime();
var time2 = new Date(date2).getTime();
var time = new Date(date).getTime();
if(time1 < time){
jsdate1.val('');
ymPrompt.errorInfo({message:'起始时间不可以小于当前时间!',title:'友情提示'});
return;
}
if(time1 > time2){
jsdate2.val('');
ymPrompt.errorInfo({message:'终止时间不可以小于起始时间!',title:'友情提示'});
return;
}else if(time1 == time2){
flag = 2;
}else{
flag = 3;
}
}