Convert Timestamp To User-friendly Format – relative-time.js

Category: Date & Time , Javascript | March 28, 2026
AuthoryairEO
Last UpdateMarch 28, 2026
LicenseMIT
Views615 views
Convert Timestamp To User-friendly Format – relative-time.js

A lightweight (less than 1kb), standalone relative time JavaScript library that converts timestamps to human-readable time format such as “5 mins ago”, “in 7 days”, and so on.

How to use it:

1. Install and import the relative-time.js.

# NPM
$ npm i @yaireo/relative-time
import RelativeTime from '@yaireo/relative-Time'

2. Or load the relative-time.js JavaScript library in the document.

<script src="relative-time.min.js"></script>

3. Initialize the relative-time.js.

const relativeTime = new RelativeTime();

4. Custom local is supported as well.

const relativeTimeSpanish = new RelativeTime({ 
      locale: 'fr' 
});

5. Convert timestamps to relative time as follows:

relativeTime.from(new Date('10/20/1984'))
=> 37 years ago

Changelog:

v1.1.0 (03/28/2026)

  • Bugfix

You Might Be Interested In:


Leave a Reply