Created
April 11, 2022 08:28
-
-
Save ratul16/337a31ade199f28acc19d6e29f325c71 to your computer and use it in GitHub Desktop.
Generate Time list both for 12/24 hour format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var x = 5; //minutes interval | |
var times = []; // time array | |
var tt = 0; // start time | |
var ap = ['AM', 'PM']; // AM-PM | |
//loop to increment the time and push results in array | |
for (var i=0;tt<24*60; i++) { | |
var hh = Math.floor(tt/60); // getting hours of day in 0-24 format | |
var mm = (tt%60); // getting minutes of the hour in 0-55 format | |
times[i] = ("0" + (hh % 12)).slice(-2) + ':' + ("0" + mm).slice(-2) + ap[Math.floor(hh/12)]; // pushing data in array in [00:00 - 12:00 AM/PM format] | |
tt = tt + x; | |
} | |
// console.log(times); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment