Created
January 8, 2012 21:23
-
-
Save kylerush/1579745 to your computer and use it in GitHub Desktop.
JavaScript epoch time convert number prototype
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
Number.prototype.timeLeft = function(){ | |
var days = Math.floor(this / 86400); | |
var hours = Math.floor((this - (days * 86400)) / 3600); | |
var minutes = Math.floor((this - ((hours * 3600) + (days * 86400))) / 60); | |
var seconds = this - ((days * 86400) + (hours * 3600) + (minutes * 60)); | |
var result = new String(); | |
if((days > 0) === true){result += days + ' days,';} | |
if((hours > 0) === true){result += ' ' + hours + ' hours, ';} | |
if((minutes > 0) === true){result += ' ' + minutes + ' minutes,';} | |
if((seconds > 0)){result += ' ' + seconds + ' seconds,';} | |
result = result.slice(0, -1); | |
return result; | |
} |
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
Number.prototype.timeLeft=function(){var days=Math.floor(this/86400);var hours=Math.floor((this-(days*86400))/3600);var minutes=Math.floor((this-((hours*3600)+(days*86400)))/60);var seconds=this-((days*86400)+(hours*3600)+(minutes*60));var result=new String();if((days>0)===true){result+=days+' days,';}if((hours>0)===true){result+=' '+hours+' hours, ';}if((minutes>0)===true){result+=' '+minutes+' minutes,';}if((seconds>0)){result+=' '+seconds+' seconds,';}result=result.slice(0,-1);return result;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment