Home > front end >  Time to determine
Time to determine

Time:01-01

If after 18:30 at 5 PM this time range between
A=1
If not after 18:30 at 5 PM this time range between
A=2
Js, how to write

CodePudding user response:

<script>
The 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 & amp; & M>=30 | | tomorrowh & lt;
=5){
Alert (" a==1 ");
}
The else
{
Alert (" a==2 ");
}

}

Window. The onl oad=function () {
GetDay ();
}
</script>

CodePudding user response:

 
The function getA (STR) {

Var initdate=new Date (STR);//need to decide for time
Var startDate=new Date (STR). SetHours (5, 0);//return 5 points on the day of the timestamp
Var endDate=new Date (STR). SetHours (18, 30);//return the 18:30 timestamp
If (initdate> EndDate | | initdate
Return 1
}
The else {
Return 2
}

}

GetA (' at 11:40 2020/12/31)

CodePudding user response:

 var n=new Date () 
Var t=n.g etHours () * 100 + n.g etMinutes ()
Var a=t & gt; 500 & amp; & T & lt; 1830? 2:1

CodePudding user response:

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;
}
The console. The log (a);

CodePudding user response:

 
The function f (s) {
The return of s & gt;="05:00" & amp; & S & lt;="him"? 2:1;
}
Alert (f (" 04:59 "));
At 19:00 alert (f (" "));
Alert (f (" prefer "));
Alert (f (" 23:59 "));
Alert (f ("; "));
Alert (f (" 06:50 "));
  • Related