一、字符串转化为时间并比较
第一种适用于:20100823这种字符串格式
function dateValid(){
var bd = document.getElementByIdx_x_x("sStartSaveDate").value;
var beginDate = newDate(bd.replace(/^(\d{4})(\d{2})(\d{2})$/,"$1/$2/$3"));
var ed = document.getElementByIdx_x_x("sEndSaveDate").value;
var endDate = newDate(ed.replace(/^(\d{4})(\d{2})(\d{2})$/,"$1/$2/$3"));
if(beginDate >= endDate){
alert("结束时间必须大于开始时间!");
return false;
}else{
document.getElementByIdx_x_x('searchform').submit();
}
}
第二种适用于:2010-08-23这种字符串格式
function dateValid(){
var beginDate = newDate(document.getElementByIdx_x_x("sStartSaveDate").value.replace(/-/g,"/"));
var endDate = newDate(document.getElementByIdx_x_x("sEndSaveDate").value.replace(/-/g,"/"));
if(beginDate >= endDate){
alert("结束时间必须大于开始时间!");
return false;
}else{
document.getElementByIdx_x_x('searchform').submit();
}
第三种适用于:2010/08/23这种字符串格式
function dateValid(){
var beginDate = newDate(document.getElementByIdx_x_x("sStartSaveDate").value);
var endDate = newDate(document.getElementByIdx_x_x("sEndSaveDate").value);
if(beginDate >= endDate){
alert("结束时间必须大于开始时间!");
return false;
}else{
document.getElementByIdx_x_x('searchform').submit();
}
}
二、时间转化为字符串
var time