I’ve looked up different options to change the format but im not sure if im doing it right since none work.
Thank you in advance.
let hrs = document.getElementById(hours)
let min = document.getElementById(minute)
let sec = document.getElementById(second)
setInterval(()=>{
let currenTime = new Date();
hours.innerHTML = (currenTime.getHours()<10?"0":"") + currenTime.getHours();
minute.innerHTML = (currenTime.getMinutes()<10?"0":"") + currenTime.
getMinutes();
second.innerHTML = (currenTime.getSeconds()<10?"0":"")+ currenTime.
getSeconds();
},1000)
if(hours == 0){
hours = 12;
}
3
Answers
Use the
hour12
option of thetoLocaleTimeString()
method.