Skip to content

Instantly share code, notes, and snippets.

@Banhawy
Last active April 10, 2019 14:19
Show Gist options
  • Save Banhawy/28089c16ad2c6d9a116a35bf51be2ebd to your computer and use it in GitHub Desktop.
Save Banhawy/28089c16ad2c6d9a116a35bf51be2ebd to your computer and use it in GitHub Desktop.
function getRemainingTime(endDate){
// Time difference betwwen now and deadline in milliseconds
let timeDifference = Date.parse(endDate) - Date.parse(new Date())
let seconds = Math.floor( (timeDifference/1000) % 60 )
let minutes = Math.floor( (timeDifference/1000/60) % 60 )
let hours = Math.floor( (timeDifference *60*60) % 24 )
let days = Math.floor( timeDifference/ (1000*60*60*24) )
return `Countdown ${days} Days, ${hours} Hours, ${minutes} minutes, ${seconds} seconds`
}
const deadline = "April 13 2019 23:59:59 GMT+0200"
console.log(getRemainingTime(deadline));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment