Skip to content

Instantly share code, notes, and snippets.

@alirezas
Created February 13, 2017 10:49
Show Gist options
  • Save alirezas/4b4488d6f9eced7b65ca9c5f73a52230 to your computer and use it in GitHub Desktop.
Save alirezas/4b4488d6f9eced7b65ca9c5f73a52230 to your computer and use it in GitHub Desktop.
Calculate remaining time with vanilla js
var deadline = '2017-03-15';
function getTimeRemaining(endtime){
var t = Date.parse(endtime) - Date.parse(new Date());
var seconds = Math.floor( (t/1000) % 60 );
var minutes = Math.floor( (t/1000/60) % 60 );
var hours = Math.floor( (t/(1000*60*60)) % 24 );
var days = Math.floor( t/(1000*60*60*24) );
return {
'total': t,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment