0

I have current hour and I want to count how many hours have passed since the start of the night. For example night started at 19:00 and current hour is 4:00, how can I calculate this (especially it must work in both cases e.g. 23:00 and 4:00)? I only have this:

now = new Date(),
now = now.getHours();
night_start = 19;
Konrad Kalemba
  • 1,119
  • 10
  • 20

1 Answers1

0

You can doit like this

now = new Date(),
now = now.getHours();
night_start = 19;

var hours = ((now - night_start)<0?24:0)+( (now - night_start));
Khalid
  • 4,594
  • 5
  • 25
  • 50