Get Time Ago
Returns a human-readable relative time string based on a given timestamp.
| Category | Dates |
| Author | Pol Gubau |
| Since | 1.0.0 |
| Last Updated | 2025-03-15 |
| Type | Sync |
| Compatibility | Universal |
Example
Input
getTimeAgo(1616161600000)Output:
2 days ago
Input
getTimeAgo(1616161600000, { locale: 'es' })Output:
hace 2 dÃas
Return
A human-readable string indicating the relative time (e.g., '2 days ago').
Type: string
Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| timestamp | number | null | Yes | The timestamp to compare the current time against, in milliseconds. |
| options | GetTimeAgoOptions | { locale: undefined } | No | Optional settings, including the locale for formatting the relative time. |
Notes
This function computes the difference between the current time and the provided timestamp, and returns a formatted string such as 'X days ago', 'X hours ago', or 'X minutes ago', based on the elapsed time.
Tags
- time
- date
- relativeTime
- intl
- locale