timeconvert
Convert milliseconds to short time.
Filename pattern: *.js
const msToShort = (milliseconds) => {
const seconds = Math.floor(milliseconds / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const units = [
{ unit: 'h', value: hours },
{ unit: 'm', value: minutes % 60 },
{ unit: 's', value: seconds % 60 },
{ unit: 'ms', value: milliseconds % 1000 },
];
return units
.filter((unit) => unit.value > 0)
.map(({ unit, value }) => `${value}${unit}`)
.join(' ');
};