Created
February 13, 2017 10:49
-
-
Save alirezas/4b4488d6f9eced7b65ca9c5f73a52230 to your computer and use it in GitHub Desktop.
Calculate remaining time with vanilla js
This file contains 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
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