Bento/js/time.js

43 lines
1010 B
JavaScript
Raw Normal View History

2020-08-14 12:28:56 -05:00
window.onload = displayClock();
function displayClock() {
const monthNames = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
];
2020-08-22 20:02:23 -05:00
// Set to true to use a 12 hour date format
var format_12hour = false;
2020-08-14 12:28:56 -05:00
var d = new Date();
var mm = monthNames[d.getMonth()];
var dd = d.getDate();
var min = (mins = ('0' + d.getMinutes()).slice(-2));
var hh = d.getHours();
2020-08-22 20:02:23 -05:00
var ampm = '';
if (format_12hour) {
ampm = hh >= 12 ? ' pm' : ' am';
hh = hh % 12;
hh = hh ? hh : 12; //show mod 0 as 12
}
2020-08-14 12:28:56 -05:00
document.getElementById('hour').innerText = hh;
document.getElementById('separator').innerHTML = ' : ';
2020-08-22 20:02:23 -05:00
document.getElementById('minutes').innerText = min + ampm;
2020-08-14 12:28:56 -05:00
2020-08-29 22:47:08 -05:00
document.getElementById('month').innerText = mm;
document.getElementById('day').innerText = dd;
2020-08-14 12:28:56 -05:00
setTimeout(displayClock, 1000);
}