Last active
June 22, 2019 16:30
-
-
Save monis01/14ed546234d86505e97f8521e4b59ccd to your computer and use it in GitHub Desktop.
it's a timer with proper addition of zeroes
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(){ | |
let todayDate = new Date(), | |
hour = todayDate.getHours(), | |
mins = todayDate.getMinutes(), | |
sec = todayDate.getSeconds() ; | |
const amPm = hour>=12 ? 'PM' : 'AM' ; | |
//12 hours format | |
hour = hour % 12 || 12 ; | |
const timeOutPut = `${addZero(hour)} : ${addZero(mins)} : ${addZero(sec)}` ; | |
console.log(timeOutPut); | |
setTimeout(showTime,1000) | |
} | |
| |
showTime() ; | |
| |
function addZero(n){ | |
return (parseInt(n,10) < 10 ? '0' : '' ) + n ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment