This article mainly introduces the JS time comparison example, the code is simple, after running can see the result, the need friend can refer to the following
Code as follows: <html> <head> <script language= "javascript" type= "Text/javascript" > /** Date comparison **/ function comparedate (strdate1,strdate2) { var date1 = NE W Date (Strdate1.replace (/-/g, "/")); var date2 = new Date (Strdate2.replace (/-/g, "/")); return date1-date2; &NBSP /** comparison **/ function Docompare () { var strDate1 = Document.get Elementbyid ("StrDate1"). Value; var strDate2 = document.getElementById ("StrDate2"). Value; var result = Comparedate (STRDATE1,STRDATE2); if (result>0) { alert ("StrDate1 later than StrDate2"); }else if (result<0) { alert ("strDate1 earlier than StrDate2"); }else if (result==0) { alert ("strDate1 equals StrDate2"); } &nbs P </script> </head> <body> <input type= "text" id= "strDate1" name= "strDate1" value= "2012-07-01"/> <input type= " Text "id=" StrDate2 "name=" StrDate2 "value=" 2012-08-01 "/> <input type=" button "id=" Comparebtn "Name=" Comparebtn "value=" compares "onclick=" docompare (); /> </body> </html>