前台判断开始时间是否小于结束时间

         // 判断开始时间是否小于结束时间
if ($("#txtBeginTime").length > 0 && $("#txtEndTime").length > 0) {
if (Date.parse(TimeFormatToSQL($("#txtBeginTime").val()).replace("-", "/")) > Date.parse(TimeFormatToSQL($("#txtEndTime").val()).replace("-", "/"))) {
alert("开始时间不能大于结束时间!");
// $("#txtBeginSearchTimeByBE").focus();
return;
 


///<summary>
///    将传递的时间值转换为SQL识别的时间格式
///<param name="strTime">时间(正常的页面显示时间格式)</param>
///</summary>
function TimeFormatToSQL(strTime) {
var strResult = "";
var strTemp = "";
for (var i = 0; i < strTime.length; i++) {
strTemp = strTime.substr(i, 1);
if (strTemp == "" || strTemp == "")
strResult += "-";
else
if (strTemp == "" || strTemp == "") {
if (strTemp == "")
strResult += "|";
else
strResult += "";
}
else
if (strTemp == "" || strTemp == "")
strResult += ":";
else
strResult += strTemp;
}
var strArgDateTime = strResult.split('|'); //此时的时间格式可能为2010-11-11 11: 或2010-11-11 11等格式
if (strArgDateTime.length == 1) {
//日期部分进行处理
var strArgDate = strArgDateTime[0].split('-'); //此时对时间部分进行处理,可能为11: 11 或11:00等格式
if (strArgDate.length == 2) {
if (strArgDate[1].length < 1)
strResult = strArgDate[0];
else
strResult = strArgDateTime[0] + "-01";
} else
if (strArgDate.length == 3) {
if (strArgDate[2].length < 1)
strResult = strArgDate[0] + "-" + strArgDate[1] + "-01";
}
}
else
if (strArgDateTime.length == 2) {
//时间部分进行处理
var strArgTime = strArgDateTime[1].split(':'); //此时对时间部分进行处理,可能为11: 11 或11:00等格式
if (strArgTime.length == 1) {
strResult = strArgDateTime[0] + " " + strArgDateTime[1] + ":00:00"
} else
if (strArgTime.length == 2) {
if (strArgTime[1].length < 1)
strResult = strArgDateTime[0] + " " + strArgDateTime[1] + "00"
else
strResult = strArgDateTime[0] + " " + strArgDateTime[1] + ":00"
} else
if (strArgTime.length == 3) {
if (strArgTime[2].length < 1)
strResult = strArgDateTime[0] + " " + strArgDateTime[1] + "00"
}
}
return strResult;
}

 

posted on 2012-02-23 17:27  张扬个性,敢为天下先  阅读(1083)  评论(0编辑  收藏  举报