Created
February 19, 2018 22:57
-
-
Save caglarorhan/ba1df52c7691b723fedb7c4311cecc84 to your computer and use it in GitHub Desktop.
Time -hour-minute-second showing 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
function correct(income){ | |
income=income.toString(); | |
if(income.length<2){income = "0"+income} | |
return income; | |
} | |
window.addEventListener('load',function(){ | |
var targetElementId='OclockDiv'; | |
var refreshFrequency=1000; //1 second =1000miliseconds | |
window.setInterval(function(){ | |
var d = new Date(); | |
var dHour = correct(d.getHours()); | |
var dMinute = correct(d.getMinutes()); | |
var dSecond = correct(d.getSeconds()); | |
document.getElementById(targetElementId).innerText="Time is: "+ dHour +":"+dMinute+":"+dSecond; | |
},refreshFrequency); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment