Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does currentTime fall between 18:00 and 2:00

I have a bar timetable with dynamic open and closing times and I have to calculate if currentTime falls within today's opening hours.

The problem is the open and closing times aren't in the same day. How does one calculate if currentTime falls within a range of specific times across multiple days?

I'm using jquery on this project.

like image 800
user909410 Avatar asked Jul 20 '12 11:07

user909410


People also ask

How do you find the time between two times?

First, identify the starting and an ending time. The goal is to subtract the starting time from the ending time under the correct conditions. If the times are not already in 24-hour time, convert them to 24-hour time. AM hours are the same in both 12-hour and 24-hour time.

How do I calculate my hours?

To find the total hours, subtract the time the employee clocked in from when they clocked out.

How do you convert time?

To convert time to a number of hours, multiply the time by 24, which is the number of hours in a day. To convert time to minutes, multiply the time by 1440, which is the number of minutes in a day (24*60). To convert time to seconds, multiply the time time by 86400, which is the number of seconds in a day (24*60*60 ).


1 Answers

if you use new Date().getTime(); this will return the number of miliseconds since a particulular time (this happens to be 1st January 1970).

If you do this for both your start and end time as well as your current time, if your current time lies between start and end then it will be greater than the start miliseconds and less than the end miliseconds.

Just a note, instead of Date().getTime(); you can actually do it as +new Date; something I learned from looking around the web. Google Wins again :). This is because the + essentially casts the date to an int.

like image 176
Jon Taylor Avatar answered Oct 06 '22 21:10

Jon Taylor