如果在晚上18:30以后早上5點之間 這個時間范圍內
a=1
如果不在晚上18:30以后早上5點之間 這個時間范圍內
a=2
js怎么寫呢
uj5u.com熱心網友回復:
<script>function getDay()
{
var todayD = new Date();
var tomorrowD = new Date();
tomorrowD.setDate(tomorrowD.getDate()+1);
var tomorrowh = tomorrowD.getHours();
var h = todayD.getHours();
var m = todayD.getMinutes();
alert(h+":"+m);
if(h>=18 && m>=30 || tomorrowh <= 5)
{
alert("a==1");
}
else
{
alert("a==2");
}
}
window.onload= function(){
getDay();
}
</script>
uj5u.com熱心網友回復:
function getA(str){
var initdate=new Date(str); //獲取需要判斷的時間
var startDate=new Date(str).setHours(5,0); // 回傳當天5點的時間戳
var endDate=new Date(str).setHours(18,30); //回傳當天18:30的時間戳
if(initdate>endDate || initdate<startDate){ //如果需要判斷的時間戳小于5點的或者大于18:30回傳1 否則回傳2
return 1
}
else {
return 2
}
}
getA('2020/12/31 11:40')
uj5u.com熱心網友回復:
var n = new Date()
var t = n.getHours() * 100 + n.getMinutes()
var a = t > 500 && t < 1830 ? 2 : 1
uj5u.com熱心網友回復:
var a=1;var nowTime=Date.now();
var start=new Date(nowTime.getYear(), nowTime.getMonth(), nowTime.getDay(), 18, 30,0);
var end=new Date(nowTime.getYear(), nowTime.getMonth(), nowTime.getDay()+1, 5, 0,0);
if(start<=nowTime&&nowTime<=end) {
a = 1;
} else {
a = 2;
}
console.log(a);
uj5u.com熱心網友回復:
function f(s) {
return s >= "05:00" && s <= "18:30" ? 2 : 1;
}
alert(f("04:59"));
alert(f("19:00"));
alert(f("00:00"));
alert(f("23:59"));
alert(f("18:29"));
alert(f("06:50"));
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/243071.html
標籤:JavaScript
上一篇:求助:bootstrap-table.min.js:7 Uncaught TypeError: Cannot assign to read only prope
