如下面的示例中所述,我想创建一个以15分钟为间隔递增的数组。无论getTime()
如何,数组都应从 12.00 AM 开始,直到 11.45 PM 示例:
[12.00 AM, 12.15 AM, 12.45 AM, 1.00 AM ... 11.45 P.M.]
答案 0 :(得分:3)
谢谢你的期待。我找到了我需要的解决方案。
var hours, minutes, ampm;
var time = [];
for(var i = 0; i <= 1440; i += 15){
hours = Math.floor(i / 60);
minutes = i % 60;
if (minutes < 10){
minutes = '0' + minutes; // adding leading zero
}
ampm = hours % 24 < 12 ? 'AM' : 'PM';
hours = hours % 12;
if (hours === 0){
hours = 12;
}
time.push(hours + ':' + minutes + ' ' + ampm);
}
document.getElementById("Time").innerText = time ;