Skip to content

Instantly share code, notes, and snippets.

View clavisound's full-sized avatar
🏠
Working from home

clavisound

🏠
Working from home
View GitHub Profile
@clavisound
clavisound / formatDuration_seconds.js
Last active July 28, 2025 17:30 — forked from zourdyzou/formatDuration.js
formatting a duration (in millisecond) to human readable format using javascript
const formatDuration = s => {
if (s < 0) s = -s;
const time = {
day: Math.floor(s / 86400),
hour: Math.floor(s / 3600) % 24,
minute: Math.floor(s / 60) % 60,
second: Math.floor(s) % 60
};
return Object.entries(time)
.filter(val => val[1] !== 0)