Search
 
SCRIPT & CODE EXAMPLE
 

HTML

am pm time html javascript

<script>
function startTime() {
    var today=new Date();
    var h=today.getHours();
    var m=today.getMinutes();
    var s=today.getSeconds();
    var ampm = "";
    m = checkTime(m);
    s = checkTime(s);

    if (h > 12) {
        h = h - 12;
        ampm = " PM";
    } else if (h == 12){
        h = 12;
        ampm = " PM";
    } else if (h < 12){
        ampm = " AM";
    } else {
        ampm = "PM";
    };

    if(h==0) {
    h=12;
    }

document.getElementById('Time').innerHTML = h+":"+m+":"+s+ampm;
var t = setTimeout(function(){startTime()},500);
}
startTime();

function checkTime(i) {
    if (i<10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;
}
</script>

<body onload='startTime()'>
  <div id='Time'></div> <!-- use some css with #Time -->
</body>
Comment

PREVIOUS NEXT
Code Example
Html :: ionic button trigger ion-datetime 
Html :: html required checkbox 
Html :: how to add a link in image 
Html :: bootstrap 5 modal 
Html :: html link favicon 
Html :: html href click not refresh 
Html :: what is dir attribute in html 
Html :: vue js v-for with index 
Html :: html basic code 
Html :: bootstrap5 lineheight 
Html :: bootstrap 4 selectpicker 
Html :: tab image code 
Html :: pyscript python html 
Html :: html type file extension 
Html :: twig default 
Html :: what is the difference between span and div 
Html :: calculator in html 
Html :: html meta tags for seo 
Html :: how to summon an entity with a tag 
Html :: bootstrap modal popup backdrop false 
Html :: img src data base64 
Html :: did not expect server html to contain a div in div 
Html :: add a html form 
Html :: samp in html 
Html :: how to comment in html 
Html :: iframe attributes 
Html :: change body font 
Html :: vimeo sdk 
Html :: hambuerger button svg 
Html :: soup to html file 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =