Skip to content

Instantly share code, notes, and snippets.

@tmountain
Created September 16, 2014 19:16
Show Gist options
  • Save tmountain/270ca27db08483768bd1 to your computer and use it in GitHub Desktop.
Save tmountain/270ca27db08483768bd1 to your computer and use it in GitHub Desktop.
dateParts = function(seconds)
{
month = 86400 * 30;
week = 86400 * 7;
day = 86400;
hour = 3600;
minute = 60;
// results
months = 0;
weeks = 0;
days = 0;
hours = 0;
minutes = 0;
if (seconds >= month) {
months = Math.floor(seconds / month);
seconds = seconds % month;
}
if (seconds >= week) {
weeks = Math.floor(seconds / week);
seconds = seconds % week;
}
if (seconds >= day) {
days = Math.floor(seconds / day);
seconds = seconds % day;
}
if (seconds >= hour) {
hours = Math.floor(seconds / hour);
seconds = seconds % hour;
}
if (seconds >= minute) {
minutes = Math.floor(seconds / minute);
seconds = seconds % minute;
}
return {"Months" : months, "Weeks" : weeks, "Days" : days, "Hours" : hours, "Minutes" : minutes};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment