I
I
Ilya Plotnikov2014-10-26 22:52:21
Node.js
Ilya Plotnikov, 2014-10-26 22:52:21

How to determine the time interval on a node?

I'm trying to write a greenhouse lighting control in node.js.
I need to turn on the relay in the range from 22:00 to 6:00 and from 6:00 to 22:00 do not turn on the relay. I created two variables

var nightStart = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 22, 00, 00);
var dayStart =   new Date(now.getFullYear(), now.getMonth(), now.getDate(), 06, 00, 00);

And then it took them away from now, but, as it turned out, the code did not work at night and the program still thought that it was daytime.
How else can you determine which interval includes the current time?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel, 2014-10-26
@ilyaplot

if (now < nightStart && now > dayStart){
 //делаем то, что с 6:00 до 22:00
}else{
 //делаем то, что с 22:00 до 6:00
}

A
Andrey Zenkov, 2014-10-27
@andreyzenkov

Yuzai moment.js is the best library for working with time and dates.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question