Formatting Utilities

Format Duration

Converts numeric seconds into human-readable duration strings like "2h 15m 30s" or "1d 4h 22m". Access via MCP in Cursor or Claude Code, or REST at GET /v1/format/duration. Pass raw seconds (3661) and get formatted output ("1h 1m 1s"). Handles everything from milliseconds to years with precise, deterministic formatting.

API Endpoint

GET /v1/format/duration

Code Examples

curl "https://tinyfn.io/v1/format/duration" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/format/duration', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/format/duration',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's formatting tools:

{
  "mcpServers": {
    "tinyfn-format": {
      "url": "https://tinyfn.io/mcp/format",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How do I format seconds into readable duration with MCP?

Use the format_duration tool in your MCP-enabled editor with the seconds parameter. For example, 7323 seconds becomes "2h 2m 3s".

What duration formats does the API support?

Returns compact format like "1d 2h 30m 45s" by default. Handles fractional seconds, supports units from milliseconds to years, and omits zero values for cleaner output.

Can I format durations longer than a day?

Yes, supports any duration length. 172800 seconds becomes "2d", 90061 seconds becomes "1d 1h 1m 1s". No upper limit on input values.

Does it handle fractional seconds or milliseconds?

Yes, accepts decimal inputs. 1.5 seconds becomes "1s 500ms", and 0.123 becomes "123ms". Precision is maintained in the formatted output.

How does this compare to manual time calculation in code?

Eliminates division/modulo math and edge cases. Instead of calculating hours = seconds // 3600, use this deterministic formatter for consistent, readable results across AI agents.

Try Format Duration Now

Get your free API key and start using Format Duration in seconds.

Get Free API Key