Formatting Utilities

Format Relative Time

Converts seconds into human-readable relative time strings like "2 hours ago" or "in 3 days". Available via MCP in Cursor and other AI editors, or REST at GET /v1/format/relative-time. Pass positive values for future times, negative for past. Perfect for chat timestamps, activity feeds, or any UI needing friendly time formatting instead of raw numbers.

API Endpoint

GET /v1/format/relative-time

Code Examples

curl "https://tinyfn.io/v1/format/relative-time" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/format/relative-time', {
  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/relative-time',
    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 as relative time in MCP?

Call the format_relative_time tool with your seconds value. Negative numbers show past times ('5 minutes ago'), positive show future ('in 2 hours').

What's the difference between relative time and timestamp formatting?

Relative time shows duration from now ('3 days ago') while timestamps show exact dates ('2024-01-15'). Use relative for recent events, timestamps for historical data.

What time units does the relative time formatter support?

Automatically selects appropriate units from seconds to years. Returns the most readable format - '90 seconds' becomes '1 minute', '25 hours' becomes '1 day'.

Can I format relative time for different languages or locales?

The formatter returns English phrases only. For internationalization, you'll need to translate the output or use locale-specific formatting libraries.

How does the relative time formatter handle edge cases like zero or very large values?

Zero returns 'now', very small values round to 'just now', and extremely large values use years. Handles both positive and negative inputs gracefully.

Try Format Relative Time Now

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

Get Free API Key