Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - How to check if current time is between two different times [duplicate]

I am trying programmatically check if the current time for my web application is between two predefined times. I don't know how to get the current time and then set variables that store two predefined times. The pseudo code would look like this

if(currentTime < shiftStart && currentTime <shiftEnd)
{
   shift = 2
}

But how do I declare and setup the variables so the code works correctly.

like image 459
deadsix Avatar asked Feb 24 '26 00:02

deadsix


1 Answers

var now = Date.now();
var time1 = //whatever time1 is
var time2 = //whatever time2 is

if (now > time1 && now < time2)
{
    alert("blah"):
}
like image 143
Seano666 Avatar answered Feb 25 '26 15:02

Seano666



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!