<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<title>Document</title>
<script></script>
</head>
<body>
开始时间:<input type="datetime-local" id="startTime" />
<br />
结束时间:<input type="datetime-local" id="endTime" />
</body>
<script>
function getTime() {
if ($("#startTime").val() !== "" && $("#endTime").val() !== "") {
// console.log($("#startTime").val());
// console.log($("#endTime").val());
var oDate1 = new Date($("#startTime").val());
var oDate2 = new Date($("#endTime").val());
console.log(oDate1);
if (oDate1.getTime() > oDate2.getTime()) {
alert("第一个大");
} else if (oDate1.getTime() < oDate2.getTime()) {
alert("第二个大");
} else {
alert("相等");
}
}
}
setInterval(getTime, 1000);
// setTimeout(getTime, 2000);
</script>
</html>