使用js比较时间
作者:互联网
<!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>
标签:console,startTime,val,getTime,js,oDate1,使用,alert,比较 来源: https://blog.csdn.net/liulang68/article/details/121436842