1. JS code of comparison date
Copy 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 ("The start time cannot be greater than the end time!");
Return false;
}
</script>
2. JS comparison time and date size
Copy code code as follows:
<html>
<head>
<Title> Calendar-Comparison time and date-www.vevb.com </title>
<script type = "text/javascript" src = "calendarframework.js"> </script>
</head>
<body>
Start time: <input onFocus = "setday (this)" id = "starttime" name = "starttime">
End time: <input onFocus = "setday (this)" ID = "endtime" name = "endtime">
<input type = "Button" Onclick = "Checktime ()" Value = "Check"/>/>
</body>
<script type = "text/javascript">
checktime = function () {
var Starttime = Document.GetelementByid ("Starttime"). Value;
var Endtime = Document.GetelementByid ("Endtime"). Value;
compareCalendar (Starttime, Endtime);
}
// Compare the size a few days ago
Function comparedate (CheckstartDate, CheckendDate) {
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 starts time greater than the 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 endateTemp = enddate.split ("");
var arrstartdate = StartDateTemp [0] .split ("-");
var arbitDate = enddateTemp [0] .split ("-");
var arrstarttime = StartDateTemp [1] .split (":");
var arreadtime = enddateTemp [1] .split (":");
Var AllstartDate = New Date (ArrtartDate [0], ArrtartDate [1], ArrtartDate [2], ArrtartTime [0], ArrtartTime [1], Arrtarttime [2]);
Var Allendate = New Date (ArrendDate [0], ArrendDate [1], ArrendDate [2], Arrendtime [0], Arrendtime [1], Arrendtime [2]);
ifstartDate.gettime ()> = Allendate.gettime ()) {) {
Alert ("Starttime cannot be greater than Endtime, cannot pass");
Return false;
} Else {
alert ("Starttime is less than endtime, so passed");
Return true;
}
} Else {
Alert ("Time can't be empty");
Return false;
}
}
// Comparison date, time size
Function CompareCalendar (StartDate, EndDate) {
if (StartDate.indexof ("")! = -1 && Enddate.indexof ("")! = -1) {
// Including time, date
Comparetime (StartDate, Enddate);
} Else {
// Do not include time, only contains the date
comparedate (StartDate, Enddate);
}
}
</script>
</html>