timeago.js formats dates as relative phrases such as "3 hours ago" for browsers and Node, with i18n and optional live DOM updates.
Overview
timeago.js is a small JavaScript library for turning timestamps into human-readable relative time strings. It works as a compact helper that can format Date values, timestamps, or date strings and keep labels current in the page when elements carry datetime attributes.
The API centers on a handful of calls: format for one-off strings, render and cancel for automatic updates on selected DOM nodes, and register for adding locales. English and Chinese are included by default, and additional languages can be registered with locale functions.
The package runs in browsers and Node, ships without dependencies, and can be installed through npm or loaded from a CDN. A separate React wrapper and Python port are mentioned as related projects.
Because labels update in the browser, pages can stay cache-friendly while still showing fresh "time ago" text after load. Programmatic formatting with different locales is also supported.
Key features
- Relative time phrases from timestamps
- Real-time DOM rendering
- Built-in English and Chinese locales
- Custom locale registration
- Works in browser and Node
- No dependencies
- npm and CDN installation
- format, render, and cancel APIs
Use cases
- Showing "time ago" labels in web UIs
- Refreshing relative timestamps after page cache
- Localized datetime display in JavaScript apps
- Lightweight timestamp formatting without moment.js