Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const SECOND = 1000;
- const MINUTE = SECOND * 60;
- const HOUR = MINUTE * 60;
- const DAY = HOUR * 24;
- const TIME = {
- second: SECOND,
- minute: MINUTE,
- hour: HOUR,
- day: DAY,
- };
- const formatNumber = (n: number) => n < 10 ? `0${n}` : n;
- function getTimerData(next: number) {
- const days = Math.floor(next / TIME.day);
- const hours = Math.floor(next / TIME.hour - days * 24);
- const minutes = Math.floor(next / TIME.minute - days * 24 * 60 - hours * 60);
- const seconds = Math.floor(next / TIME.second - minutes * 60 - days * 24 * 60 * 60 - hours * 60 * 60);
- return {
- days,
- hours: formatNumber(hours),
- minutes: formatNumber(minutes),
- seconds: formatNumber(seconds),
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement