I am working on a live html and javascript clock. This code is almost complete, but I do not want the clock to display military time,
Here's what I've tried:
<!DOCTYPE html>
<html>
<head>
<script>
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById('time').innerHTML =
h + ":" + m + ":" + s + `<strong>a.m.</strong>`;
var t = setTimeout(startTime, 500);
}
function checkTime(i) {
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
function unMilitary() {
if (h = 13) {h = 1}
if (h = 14) {h = 2}
if (h = 15) {h = 3}
if (h = 16) {h = 4}
if (h = 17) {h = 5}
if (h = 18) {h = 6}
if (h = 19) {h = 7}
if (h = 20) {h = 8}
if (h = 21) {h = 9}
if (h = 22) {h = 10}
if (h = 23) {h = 11}
if (h = 24) {h = 12}
return h;
}
</script>
</head>
<body onload="startTime()">
<div id="time"></div>
<p>
(for those of you who are viewing this time in midday, it is displaying military time.)
</p>
</body>
</html>
The unMilitary
function isn't working, any suggestions?
Here is the code live in jsfiddle.