I would like to display this as something like: 4:26 PM.
But what I keep getting is: 04:26 PM.
If I remove the hour and minute options
from toLocaleTimeString()
, it works, but it also displays seconds, which I don't want.
myClock();
function myClock() {
var d = new Date().toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
document.getElementById("clock").innerHTML = d;
}
setInterval(myClock, 1000);
<html>
<head>
<title></title>
</head>
<body>
<div id="clock"></div>
<script src="testStorage.js"></script>
</body>
</html>
Read more here: https://stackoverflow.com/questions/66268522/tolocaletimestring-always-showing-leading-zero
Content Attribution
This content was originally published by scott.schaffer at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.