Created
April 24, 2020 12:27
-
-
Save Varad2305/22a18b4a36c0fd66d3c384005519afc8 to your computer and use it in GitHub Desktop.
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 updateClock(){ | |
var currentTime = new Date(); | |
var currentHours = currentTime.getHours(); | |
var currentMins = currentTime.getMinutes(); | |
var currentSecs = currentTime.getSeconds(); | |
currentMins = ( currentMins < 10 ? "0" : "" ) + currentMins; | |
currentSecs = ( currentSecs < 10 ? "0" : "" ) + currentSecs; | |
var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM"; | |
currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours; | |
currentHours = ( currentHours == 0 ) ? 12 : currentHours; | |
var currentTimeString = currentHours + ":" + currentMins + ":" + currentSecs + " " + timeOfDay; | |
document.getElementById("clock").firstChild.nodeValue = currentTimeString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment