Js frontend determines whether the start time is earlier than the end time

Source: Internet
Author: User

Copy codeThe Code is as follows:
// Determine whether the start time is earlier 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 later than the end time! ");
// $ ("# TxtBeginSearchTimeByBE"). focus ();
Return;



/// <Summary> /// convert the passed time value to the time format recognized by SQL.
/// <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 = "second "){
If (strTemp = "day ")
StrResult + = "| ";
Else
StrResult + = "";
}
Else
If (strTemp = "Hour" | strTemp = "Minute ")
StrResult + = ":";
Else
StrResult + = strTemp;
}
Var strArgDateTime = strResult. split ('|'); // The time format may be 2010-11-11 11: Or 2010-11-11 11.
If (strArgDateTime. length = 1 ){
// Process the date part
Var strArgDate = strArgDateTime [0]. split ('-'); // process the time part, which may be in the format of 11: 11 or.
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 ){
// Process the time part
Var strArgTime = strArgDateTime [1]. split (':'); // process the time part, which may be in the format of 11: 11 or.
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.