Skip to content

Instantly share code, notes, and snippets.

@monis01
Last active June 22, 2019 16:30
Show Gist options
  • Save monis01/14ed546234d86505e97f8521e4b59ccd to your computer and use it in GitHub Desktop.
Save monis01/14ed546234d86505e97f8521e4b59ccd to your computer and use it in GitHub Desktop.
it's a timer with proper addition of zeroes
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