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">
<title>Document</title>
</head>
<body>
<script>
var date = {
isDuringDate: function (beginDateStr, endDateStr) {
let curDate = new Date(),
beginDate = new Date(beginDateStr),
endDate = new Date(endDateStr);
if (curDate >= beginDate && curDate <= endDate) {
return true;
}
return false;
}
}
console.log(date.isDuringDate('2022/03/06', '2030/09/17'));
</script>
</body>
</html>
运行效果: 好啦,希望对大家有所帮助,谢谢点赞加关注哦~
|