Im trying to store values in an Array using a loop in JavaScript. It only works partially for me.
I want to store time in an Array
There will be startTime, endTime and an interval
For example: If want to get the time from 9:00 to 10:00 with an interval of 15 minutes, it should print
09:00,09:15,09:30,09:45,10:00
but it's printing
09:00,09:15,09:30,09:45,10:00,10:15,10:30,10:45
Second what should I do if I want to get the time difference between 9:30 and 10:30? or 9:45 and 10:45?
Here is my Code:
HTML
<div id="time"></div>
JavaScript
var array = new Array();
var timeDiff = 15;
var FirstTime = 9;
var endTime = 10;
for (var xh = FirstTime; xh <= endTime; xh++) {
for (var xm = 0; xm < 60; xm += timeDiff) {
array.push(("0" + xh).slice(-2) + ':' + ("0" + xm).slice(-2));
}
};
$('#time').text(array)