This article is mainly on the JS date comparison of a simple example of the introduction of the needs of friends can come to the reference, I hope to help you all
1, compare the date size of the JS code code as follows: <script> var begindate=$ ("#beginDate"). Val (); var enddate=$ ("#endDate"). Val (); var D1 = new Date (Begindate.replace (/-/g, "/")); var d2 = new Date (Enddate.replace (/-/g, "/")); if (begindate!= "" &&enddate!= "" &&d1 >=d2) { alert (" Start time cannot be greater than end time! "); return false;   </script> 2,JS compare time and date size code as follows: <html> <head> < title>calendar-Compare time and date sizes-www.jbxue.com</title> <script type= "Text/javascript" src= " Calendarframework.js ></script> </head> <body> start time:< Input onfocus= "Setday (This)" id= "StartTime" name= "StartTime" > to end time: <input onfocus= "Setday" ( This) "id=" Endtime "name=" Endtime "> <input type=" button "onclick=" C Hecktime ()"Value=" Check "/> </body> <script type=" Text/javasc Ript "> checktime = function () { var starttime = document.getElementById (" Start Time "). Value; var endtime = document.getElementById ("Endtime"). Value; Comparecalendar (StartTime, Endtime); } //Compare days before size function comparedate (checkstartdate, checkenddate) {&nbs P var arys1= new Array (); var arys2= new Array (); if (checkstartdate!= null && checkenddate!= null) { ARYS1 =checkstartdate.split ('-'); var sdate=new Date (Arys1[0],parseint (arys1[1]-1), arys1[2]); arys2=checkenddate.split ('-'); VAR edaTe=new Date (Arys2[0],parseint (arys2[1]-1), arys2[2]); if (Sdate > Edate) { alert ("Date start time greater than end time"); return false; } else { alert ("through"); return True { } } //judgment date , Time size function comparetime (StartDate, EndDate) { if (startdate.length > 0 && enddate. Length > 0) { var startdatetemp = Startdate.split (""); var enddatetemp = Enddate.split (""); var arrstartdate = Startdatetemp[0].split ("-"); var arrenddate = Enddatetemp[0].split ("-"); var arrstarttime = Startdatetemp[1].split (":"); &nbsP var arrendtime = Enddatetemp[1].split (":"); var allstartdate = new Date (arrstartdate[0], arrstartdate[1], arrstartdate[2], arrstarttime[0], ARRSTARTTIME[1], arrstarttime[2]); var allenddate = new Date (arrenddate[0], arrenddate[1], arrenddate[2], arrendtime[0], arrendtime[1], ARRENDTIME[2]); if (allstartdate.gettime () >= allenddate.gettime ()) { Aler T ("StartTime cannot be greater than Endtime, cannot pass"); return false; } else { alert ("StartTime less than Endtime, so passed"); return True ; } } else { alert ("Time cannot be empty"); & nbsp return false; } } //Comparison date, time size function Comparecalendar (startdate, end Date) { if (Startdate.indexof ("")!=-1 && EndDate.indexof ("")!=-1 { //inclusive time, date Comparetime (StartDate, EndDate); } else { //No time included, only date &NB Sp Comparedate (StartDate, EndDate); } { </script> </html>