Skip to content

Instantly share code, notes, and snippets.

@jquery404
Last active May 16, 2018 03:42
Show Gist options
  • Save jquery404/f2227198ff27155411ba46e25c87699d to your computer and use it in GitHub Desktop.
Save jquery404/f2227198ff27155411ba46e25c87699d to your computer and use it in GitHub Desktop.
Loop from start time to end time and returns array of times [8:00AM, 8:30AM, 9:00AM, .....]
$scope.selectedInterval = 30;
$scope.updateTimeInterval = function()
{
var startTime = 8;
var endTime = 13;
var tt = startTime*60; // start at 8am
var ap = ['AM', 'PM'];
//loop to increment the time and push results in array
for (var i=0;tt<=endTime*60; i++) { // end at 13 pm
var hh = Math.floor(tt/60);
var mm = (tt%60);
$scope.times[i] = ("0" + (hh % 12)).slice(-2) + ':' + ("0" + mm).slice(-2) + ap[Math.floor(hh/12)];
tt = tt + $scope.selectedInterval;
console.log(tt);
}
console.log($scope.times);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment