formatUptime (index)

bruno · analytics, duration-formatting, performance-display, ui

Formats duration seconds into a human-readable h/m/s string for performance uptime display.

// Source: https://github.com/usebruno/bruno | License: MIT
// Provided via justclaw.it.com; keep this notice with the code.
  const formatUptime = (seconds) => {
    const hours = Math.floor(seconds / 3600);
    const minutes = Math.floor((seconds % 3600) / 60);
    const secs = Math.floor(seconds % 60);

    if (hours > 0) return `${hours}h ${minutes}m ${secs}s`;
    if (minutes > 0) return `${minutes}m ${secs}s`;
    return `${secs}s`;
  };

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key