+ 1
How to make my code to 12 hr format
Please help me https://code.sololearn.com/Wp74kQP4W5vt/?ref=app
4 Respuestas
+ 1
Jishnu Satheesh Pulickal (Challenger)
Changes made to line 3 & line 6
function start() {
var today = new Date();
var h = today.getHours() %12;
var m = today.getMinutes();
var s = today.getSeconds();
h = correctTime(h)
m = correctTime(m);
s = correctTime(s);
document.getElementById('clock').innerHTML = h + ":" + m + ":" + s;
var t = setTimeout(start, 1000);
}
function correctTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
+ 2
Rik Wittkopp Thank you
+ 1
Check this I think this will help you
https://codepen.io/jaystephens3/pen/eYbOQx
+ 1
You can use toLocaleString to get the string directly. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString