Skip to content

Instantly share code, notes, and snippets.

@vlrmprjct
Created November 29, 2018 12:35
Show Gist options
  • Select an option

  • Save vlrmprjct/b476c24b980d6002e2d418188c1ec7fa to your computer and use it in GitHub Desktop.

Select an option

Save vlrmprjct/b476c24b980d6002e2d418188c1ec7fa to your computer and use it in GitHub Desktop.
countdown from seconds #time #js
export const countdown = (function () {
const pad = t => {
return (t + '').length < 2 ? pad('0' + t + '') : t;
}
return s => {
const d = Math.floor(s / (3600 * 24));
s -= d * 3600 * 24;
const h = Math.floor(s / 3600);
s -= h * 3600;
const m = Math.floor(s / 60);
s -= m * 60;
const tmp = [];
(d) && tmp.push(d + 'd');
(d || h) && tmp.push(h + 'h');
(d || h || m) && tmp.push(m + 'm');
tmp.push(s + 's');
return tmp.join(' ');
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment