A Pen by Aaron Farrar on CodePen.
Created
September 23, 2023 18:33
-
-
Save jimf99/1d2d4d5ceaa7c45902f2f77f925a7787 to your computer and use it in GitHub Desktop.
Digital Clock In JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="MyClockDisplay" class="clock" onload="showTime()"></div> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function showTime(){ | |
var date = new Date(); | |
var h = date.getHours(); // 0 - 23 | |
var m = date.getMinutes(); // 0 - 59 | |
var s = date.getSeconds(); // 0 - 59 | |
var session = "AM"; | |
if(h == 0){ | |
h = 12; | |
} | |
if(h > 12){ | |
h = h - 12; | |
session = "PM"; | |
} | |
h = (h < 10) ? "0" + h : h; | |
m = (m < 10) ? "0" + m : m; | |
s = (s < 10) ? "0" + s : s; | |
var time = h + ":" + m + ":" + s + " " + session; | |
document.getElementById("MyClockDisplay").innerText = time; | |
document.getElementById("MyClockDisplay").textContent = time; | |
setTimeout(showTime, 1000); | |
} | |
showTime(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background: black; | |
} | |
.clock { | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translateX(-50%) translateY(-50%); | |
color: #17D4FE; | |
font-size: 60px; | |
font-family: Orbitron; | |
letter-spacing: 7px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://fonts.googleapis.com/css?family=Orbitron" rel="stylesheet" /> | |
<link href="https://fonts.googleapis.com/css?family=Aldrich" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment