In my scenario, I am trying to generate a time from current time to previous 60 min, each numbers 10 minutes difference. For example my current time is 11 then I want to generate like this: 10.30, 10.40, 10.50, 11.00.
How to achieve this current by using below code, I am getting reverse array current should be first index. How to achieve like this: 10.30, 10.40, 10.50, 11.00.
function addMinutes(date, minutes) { return new Date(date.getTime() + minutes*60000);}function () { var d = new Date(); var result = ""; for (var idx = 0; idx < 6; idx++) { var m = (((d.getMinutes() + 7.5)/15 | 0) * 15) % 60; var h = ((((d.getMinutes()/105) + .5) | 0) + d.getHours()) % 24; d = new Date(d.getYear(), d.getMonth(), d.getDay(), h, m, 0, 0); if (idx > 0) result += ", "; result += ("0" + h).slice(-2) +":" + ("0" + m).slice(-2); d = addMinutes(d, -15); } $(".answer").text("Time: " + result);});