I have 3 time stamps
StartTime: 22:30:00
EndTime: 05:00:00
CurrentTime: 03:00:00
Now if the current time lies between StartTime and EndTime, then I want to print the “CurrentTime”. So in the above example since CurrentTime is between 22:30:00 and 05:00:00, hence I wish to print it.
So I used the following code
const StartTime = new Date("2020-02-22T23:00");
const EndTime = new Date("2020-02-23T05:00");
const CurrentTime = new Date("2022-02-23T0:00");
const StartTimeHours = StartTime.toLocaleTimeString('en-US', { hour12: false });
const EndTimeHours = EndTime.toLocaleTimeString('en-US', { hour12: false });
const CurrentHours = CurrentTime.toLocaleTimeString('en-US', { hour12: false});
if (StartTimeHours < CurrentHours && CurrentHours < EndTimeHours)
{
console.log("Current Time",CurrentHours);
}
However, since 05:00:00 is less than 22:30:00, hence it is not printing the output. So how do I make it check that the EndTime is between the two time slots