A Pen by Aaron Farrar on CodePen.
Created
March 14, 2019 23:35
-
-
Save ndsamuelson/28f0eb71f50396e26754c04c7d9f3afd to your computer and use it in GitHub Desktop.
Digital Clock In JavaScript
This file contains 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"></div> |
This file contains 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 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 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