Home > Web Front-end > JS Tutorial > js frontend determines whether the start time is less than the end time_jquery

js frontend determines whether the start time is less than the end time_jquery

WBOY
Release: 2016-05-16 17:55:59
Original
1505 people have browsed it
Copy code The code is as follows:

// Determine whether the start time is less than the end time
if ($ ("#txtBeginTime").length > 0 && $("#txtEndTime").length > 0) {
if (Date.parse(TimeFormatToSQL($("#txtBeginTime").val()). replace("-", "/")) > Date.parse(TimeFormatToSQL($("#txtEndTime").val()).replace("-", "/"))) {
alert( "The start time cannot be greater than the end time!");
// $("#txtBeginSearchTimeByBE").focus();
return;



///< summary>/// Convert the passed time value into the time format recognized by SQL
///Time (normal page display time format)
///
function TimeFormatToSQL(strTime) {
var strResult = "";
var strTemp = "";
for (var i = 0; i < strTime. length; i ) {
strTemp = strTime.substr(i, 1);
if (strTemp == "year" || strTemp == "month")
strResult = "-";
else
if (strTemp == "day" || strTemp == "second") {
if (strTemp == "day")
strResult = "|";
else
strResult = "";
}
else
if (strTemp == "hour" || strTemp == "minute")
strResult = ":";
else
strResult = strTemp;
}
var strArgDateTime = strResult.split('|'); //The time format at this time may be 2010-11-11 11: or 2010-11-11 11 and other formats
if (strArgDateTime.length == 1) {
//The date part is processed
var strArgDate = strArgDateTime[0].split('-'); //The time part is processed at this time, which may be 11: 11 or 11:00 and other formats
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) {
//Time Process the part
var strArgTime = strArgDateTime[1].split(':'); //Process the time part at this time, which may be 11: 11 or 11:00 and other formats
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;
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template