/** * Formats seconds (number) to H:i:s format. * 00:12:00 * * When "short" option is set to true, will return: * 0:50 * 2:00 * 12:00 * 1:00:24 * 10:00:00 */export default function formatTimeHIS (seconds, { short = false } = {}) { const pad = num => num < 10 ? `0${num}` : num const H = pad(Math.floor(seconds / 3600)) const i = pad(Math.floor(seconds % 3600 / 60)) const s = pad(seconds % 60) if (short) { let result = '' if (H > 0) result += `${+H}:` result += `${H > 0 ? i : +i}:${s}` return result } else { return `${H}:${i}:${s}` }}
↧
Answer by artnikpro for JavaScript seconds to time string with format hh:mm:ss
↧