Skip to main content

Digital Clock JAVA script

const hourEl = document.getElementById("hour")
const minuteEl = document.getElementById("minutes")
const secondEl = document.getElementById("seconds")
const ampmEl = document.getElementById("ampm")

function updateClock(){
    let h = new Date().getHours()
    let m = new Date().getMinutes()
    let s = new Date().getSeconds()
    let ampm = "AMPM"

    if(h > 12){
        h = h- 12
        ampm = "PM"
    }

    h = h<10 ? "0" + h : h;
    m = m<10 ? "0" + m : m;
    s = s<10 ? "0" + s : s;

    hourEl.innerText = h;
    minuteEl.innerText = m;
    secondEl.innerText = s;
    ampmEl, (innerText = ampm);
    setTimeout(()=> {
        updateClock()
    }, 1000)
}

updateClock();







Comments

Popular posts from this blog

New Technology (Artificial Intelligence)

 Top 5 Emerging Technologies to Watch in 2023   Artificial Intelligence : AI continues to evolve at a rapid pace and is becoming increasingly accessible to businesses of all sizes. It is being used for automation, predictive analytics, and decision-making. AI is also starting to be integrated into a wider range of devices and products, including everything from smart home devices to self-driving cars. 5G : 5G networks are set to revolutionize the way we communicate and access the internet. With faster speeds and lower latency, 5G is poised to drive innovation across a wide range of industries, including healthcare, transportation, and entertainment.   Internet of Things (IoT) : The Internet of Things (IoT) is becoming more widespread, with more and more connected devices being added to the market every year. IoT technology enables the collection and analysis of data from these devices, leading to improved efficiency and increased automation. Virtual and Augmented Reality : Virtual and

Digital Clock HTML Script

<!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta http-equiv="X-UA-Compatible" content="IE=edge">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <title>Digital Clock</title>     <link rel="stylesheet" href="style.css"> </head> <body>     <h2>Digital Clock</h2>     <div class="clock">     <div>         <span id="hour">00</span>         <span class="text">Hours</span>     </div>     <div>         <span id="minutes">00</span>         <span class="text">minutes</span>     </div>     <div>         <span id="seconds">00</span>         <span class="text">seconds</span>     </div>     <div>