Skip to content

Instantly share code, notes, and snippets.

@Varad2305
Created April 24, 2020 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Varad2305/22a18b4a36c0fd66d3c384005519afc8 to your computer and use it in GitHub Desktop.
Save Varad2305/22a18b4a36c0fd66d3c384005519afc8 to your computer and use it in GitHub Desktop.
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