---
title: "Display the relative time from a date"
description: "Show the relative time (e.g., '2 days ago') from a given date in TypeScript."
date: "2025-10-02"
lastUpdated: "2026-03-24"
tags: ["typescript","date","relative-time","frontend"]
canonical: "/snippets/typescript/date/relative-time"
---

import { Code } from '@astrojs/starlight/components'
import Source from './relative-time.ts?raw'

Using [`Intl.RelativeTimeFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat), you can easily display the relative time from a
date in TypeScript.

<Code code={Source} lang="ts" title="relative-time.ts" wrap />
