JavaScript start and end time comparisons

Source: Internet
Author: User
The code is as follows Copy Code


Determines 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 ("Start time cannot be greater than end time!");
$ ("#txtBeginSearchTimeByBE"). focus ();
Return

<summary>///converts the passed time value to the SQL-recognized time format
<param name= "Strtime" > Time (Normal page display time format) </param>
</summary>
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 = = "Seconds") {
if (strtemp = = "Day")
Strresult + = "|";
Else
Strresult + = "";
}
Else
if (strtemp = "Time" | | strtemp = = "Min")
Strresult + = ":";
Else
Strresult + = strtemp;
}
var strargdatetime = strresult.split (' | '); This time format may be 2010-11-11 11: or 2010-11-11 11 format
if (strargdatetime.length = = 1) {
Date part to process
var strargdate = strargdatetime[0].split ('-'); The time part is processed at this point, possibly in 11:11 or 11:00 format
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 part to process
var strargtime = strargdatetime[1].split (': '); The time part is processed at this point, possibly in 11:11 or 11:00 format
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.