Skip to content

Instantly share code, notes, and snippets.

@nkint
Created August 20, 2014 21:11
Show Gist options
  • Save nkint/24426093c5e29a62803a to your computer and use it in GitHub Desktop.
Save nkint/24426093c5e29a62803a to your computer and use it in GitHub Desktop.
javascript: timestamp to human readable (hours, minutes, seconds)
// http://www.epochconverter.com
function TimeCounter(t) {
var days = parseInt(t / 86400);
t = t - (days * 86400);
var hours = parseInt(t / 3600);
t = t - (hours * 3600);
var minutes = parseInt(t / 60);
t = t - (minutes * 60);
var content = "";
if (days) content += days + " days";
if (hours || days) {
if (content) content += ", ";
content += hours + " hours";
}
if (content) content += ", ";
content += minutes + " minutes and " + t + " seconds.";
return content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment