Converting 24 hr formatted time to 12 hr format in HTML

31 Views Asked by At

I am currently trying to translate a Wallpaper Engine wallpaper from Chinese to English, part of this process is converting the 24 hours time standard to the 12 hours standard. Here is the code I believe is used to calculate the time, any help would be most appreciated! If this is not the correct section of code or if more info is needed, let me know, I'd be happy to share more!

//update time
function upDateTime(){
  var date = new Date();
  var hour = date.getHours();
  var minute = date.getMinutes();
  var second = date.getSeconds();
  if(hour < 10){hour = "0" + hour;} 
  if(minute < 10){minute = "0" + minute;}
  var times = document.getElementById("time").getElementsByTagName("p");
  times[0].innerText = hour
  times[1].innerText = minute;
  setTimeout(upDateTime, 60 - second);
  //update Day
  if(hour == 0 && upDay == true){
    upDay = false;
    pushDate();
    setTimeout(function(){
      upDay = true;
    },1000*3600*1.01);
  }
}
upDateTime();
#time{
  display: flex;
  gap: 2px;
  align-items: center;
}
<button id="time" onclick="upDateTime();">
  <p></p>
  :
  <p></p>
</button>

I attempted to read some similar Stack Overflow articles, but was unable to successfully get the time format to change due to the code not originally coming from me.

0

There are 0 best solutions below