# Relative Time Formatter API

> Relative Time Formatter converts Unix timestamps and ISO dates into readable relative time phrases. Choose between short, long, or abbreviated styles to get humanized past or future strings, millisecond differences, and unit breakdowns from seconds to years.

**Endpoint:** `GET https://api.apiverve.com/v1/relativetimeformatter`  
**Category:** Data Conversion  
**Cost:** 1 credit per call  
**Canonical page:** https://apiverve.com/marketplace/relativetimeformatter

## Overview

Relative Time Formatter works by calculating the time difference between dates and expressing it in the most appropriate unit (seconds, minutes, hours, days, weeks, months, years) with customizable formatting styles.

## Authentication

Every call carries your key in an `x-api-key` header. The same key works across the whole
APIVerve catalog — there are no per-API subscriptions. Responses always use the same three
top-level keys: `status`, `error`, and `data`.

## Example request

```bash
curl "https://api.apiverve.com/v1/relativetimeformatter?timestamp=1609459200&reference=2024-06-01T00%3A00%3A00Z&style=short" \
  -H "x-api-key: YOUR_API_KEY"
```

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `timestamp` | string | Yes | Unix timestamp in seconds or milliseconds. timestamp |
| `reference` | string | No | Date or ISO 8601 date-time to compare against (default: current time). A time and offset are used; a date alone is midnight UTC. datetime |
| `style` | string | No | Output style. default short. One of: short, long, abbreviated |

## Response fields

- `target_date` — string · The date being described
- `reference_date` — string · The date it is described relative to
- `relative_time` — string · Relative time formatted string (e.g., '2 hours ago')
- `is_past` — boolean · Whether the target date falls before the reference date
- `is_future` — boolean · Whether the target date falls after the reference date
- `difference_ms` — number · Gap between the two dates in milliseconds
- `primary_unit` — string · Primary time unit used in formatting
- `primary_value` — number · Numeric value of the time unit
- `all_units` — object · The same gap expressed in every unit
  - `all_units.years` — number · Gap in years
  - `all_units.months` — number · Gap in months
  - `all_units.weeks` — number · Gap in weeks
  - `all_units.days` — number · Gap in days
  - `all_units.hours` — number · Gap in hours
  - `all_units.minutes` — number · Gap in minutes
  - `all_units.seconds` — number · Gap in seconds
  - `all_units.milliseconds` — number · Gap in milliseconds
- `style` — string · The formatting style applied to relative_time - short, long or abbreviated

## Sample response

```json
{
  "status": "ok",
  "error": null,
  "data": {
    "target_date": "2021-01-01T00:00:00Z",
    "reference_date": "2025-12-16T22:28:24.459Z",
    "relative_time": "4 years ago",
    "is_past": true,
    "is_future": false,
    "difference_ms": -156464904459,
    "primary_unit": "year",
    "primary_value": 4,
    "all_units": {
      "years": 4,
      "months": 59,
      "weeks": 258,
      "days": 1810,
      "hours": 43462,
      "minutes": 2607748,
      "seconds": 156464904,
      "milliseconds": 156464904459
    },
    "style": "short"
  }
}
```

## Use cases

- **Social Media** — Display post timestamps as relative times like '5 minutes ago' in feeds and timelines
- **Activity Logs** — Show user activity and system events with human-readable time references
- **Notifications** — Format notification timestamps for better user comprehension and engagement
- **Analytics** — Present time-based data and metrics in accessible relative time formats

## SDKs

- **npm** — `npm install @apiverve/relativetimeformatter` (https://www.npmjs.com/package/@apiverve/relativetimeformatter)
- **PyPI** — `pip install apiverve-relativetimeformatter` (https://pypi.org/project/apiverve-relativetimeformatter/)
- **NuGet** — `dotnet add package APIVerve.API.RelativeTimeFormatter` (https://www.nuget.org/packages/APIVerve.API.RelativeTimeFormatter)
- **Source** — https://github.com/apiverve/relativetimeformatter-api

## More

- Full reference: https://docs.apiverve.com/ref/relativetimeformatter
- Get an API key: https://dashboard.apiverve.com
- Full catalog: https://apiverve.com/marketplace
