Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Convert seconds into a human readable string
- * @param {number} duration Seconds
- * @returns {string}
- */
- const durationToReadableTime = duration => {
- let tmp = duration / 60;
- let minutes = Math.floor(tmp);
- tmp = tmp - minutes;
- const seconds = Math.round(tmp * 60);
- if (minutes >= 60) {
- tmp = minutes / 60;
- const hours = Math.floor(tmp);
- tmp = tmp - hours;
- minutes = Math.round(tmp * 60);
- return `${hours}h ${minutes}m`;
- }
- return `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement