@date-js/dom-timeago

A tiny JavaScript library that transforms timestamps into live, human-readable relative dates.

npm version github stars bundle size

Default Rules

Just now
Seconds ago
Minutes ago
Hours ago
Today
Yesterday
Days ago
Same year
Older

Custom Rule

10+ years ago (custom)
const config = {
  rules: [{
    condition: function(dateInterval) {
      return dateInterval.day >= 365 * 10;
    },
    text: {
      fr: "%dd jour{%dd||s} (année %Y)",
      en: "%dd day{%dd||s} ago (year %Y)"
    }
  }]
};

DateJs. DomTimeago.start(config);