I need to find a set of hours, starting from now, every 6 hours.So if now is midnight, I want [ 0, 6, 12, 18 ].If now is 15h (3pm), I want [ 15, 21, 3, 9 ]For now I have brute-forced it:var now = new Date();var hours = [];var h = now.getHours();// add current hour (tomorrow)hours.push(h);// to add 6 hoursvar inXh = function(toAdd) {    var inh = h + toAdd;    if (inh >= 24) { inh = inh - 24; }    return inh;}; // add in 6 hourshours.push(inXh(6));// add in 12 hourshours.push(inXh(12));// add in 18 hourshours.push(inXh(18));It's incredibly ugly and verbose, and I'm sure there is a much more clever way to do it, but right now I'm too tired to calculate modulos.
Find every 6 hours from now
javascript;datetime
You are basically calculating the modulo manually by doing if (inh >= 24) { inh = inh - 24; }but JavaScript can do it for you, so the inXh() function could be written like this:var inXh = function(toAdd) {    return (h + toAdd * 6) % 24;}With that, after having declaredvar h = new Date().getHours();you have (at least) two options, choose the one you feel more elegant.OPTION 1: using for:var hours = [];for (var i = 0; i < 4; i++) hours.push(inXh(i));OPTION 2 (nicer in my opinion): using Array.map():var hours = [0, 1, 2, 3].map(inXh);which all together in one line would bevar hours = [0, 1, 2, 3].map(function(toAdd) { return (h + toAdd * 6) % 24; });