Skip to main content
Home

Built and signed on GitHub Actions

A minimal relative time string library

This package works with Node.js, Deno, Bun, BrowsersIt is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
3 months ago (2025.4.9)

Time-ago

A minimal relative time string function

JSR JSR Score GitHub License GitHub Release

Check the Documentation in JSR

Overview

The timeAgo function returns a human-readable string representing the time elapsed since a given date. It supports producing strings like "just now", "5 minutes ago", and "a year ago" for quick and simple time formatting. Supported intervals are "year", "month", "week", "day", "hour", "minute", and "second".

The timeRemaining function returns a human-readable string representing the time remaining until a given date. It supports producing strings like "in 5 seconds", "in 5 minutes", and "in a year" for quick and simple time formatting. Supported intervals are "year", "month", "week", "day", "hour", "minute", and "second".

Usage

timeAgo

import { timeAgo } from "@egamagz/time-ago";

console.log(timeAgo(new Date())); // "just now"

console.log(timeAgo(new Date(Date.now() - 1000))); // "a second ago"

console.log(timeAgo(new Date(Date.now() - 1000 * 60 * 5))); // "5 minutes ago"

console.log(timeAgo(new Date(Date.now() - 1000 * 60 * 60 * 24 * 5))); // "5 days ago"

timeRemaining

import { timeRemaining } from "@egamagz/time-ago";

console.log(timeRemaining(Date.now() + 5000)); // "in 5 seconds"

console.log(timeRemaining(Date.now() + 5 * 60 * 1000)); // "in 5 minutes"

console.log(timeRemaining(Date.now() + 3 * 60 * 60 * 1000)); // "in 3 hours"

console.log(timeRemaining(Date.now() + 60 * 60 * 1000)); // "in an hour"

// Weeks
console.log(timeRemaining(Date.now() + 3 * 7 * 24 * 60 * 60 * 1000)); // "in 3 weeks"

// Month (exact month difference)
console.log(timeRemaining(Date.now() + 30 * 24 * 60 * 60 * 1000)); // "in a month"

// Four weeks vs month example
console.log(timeRemaining(Date.now() + 4 * 7 * 24 * 60 * 60 * 1000)); // "in 4 weeks"

Installation

With Deno

deno add jsr:@egamagz/time-ago

With Bun

bunx jsr add @egamagz/time-ago

With NPM

npx jsr add @egamagz/time-ago

License

MIT License

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@egamagz/time-ago

Import symbol

import * as time_ago from "@egamagz/time-ago";
or

Import directly with a jsr specifier

import * as time_ago from "jsr:@egamagz/time-ago";

Add Package

pnpm i jsr:@egamagz/time-ago
or (using pnpm 10.8 or older)
pnpm dlx jsr add @egamagz/time-ago

Import symbol

import * as time_ago from "@egamagz/time-ago";

Add Package

yarn add jsr:@egamagz/time-ago
or (using Yarn 4.8 or older)
yarn dlx jsr add @egamagz/time-ago

Import symbol

import * as time_ago from "@egamagz/time-ago";

Add Package

vlt install jsr:@egamagz/time-ago

Import symbol

import * as time_ago from "@egamagz/time-ago";

Add Package

npx jsr add @egamagz/time-ago

Import symbol

import * as time_ago from "@egamagz/time-ago";

Add Package

bunx jsr add @egamagz/time-ago

Import symbol

import * as time_ago from "@egamagz/time-ago";