@yaireo/relative-time
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Transform timestamp or date to local relative-time


Super lightweight (< 500 bytes)   🕙   Uses native browser API


Install:

NPM / CDN / Download from this repo

npm i @yaireo/relative-time -S

Usage:

Import:

import RelativeTime from '@yaireo/relative-time'

And use:

```js
const relativeTime = new RelativeTime(); // defaults to OS locale
const relativeTimeSpanish = new RelativeTime({ locale: 'es' }); // set Spanish locale

console.log(   relativeTime.from(new Date('2015'))  )  // "6 years ago"
console.log(   relativeTimeSpanish.from(new Date('2015'))  )  // "hace 6 años"

Live demo

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.4
    1,077
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.4
    1,077
  • 1.0.3
    85
  • 1.0.2
    24
  • 1.0.1
    3
  • 1.0.0
    0

Package Sidebar

Install

npm i @yaireo/relative-time

Weekly Downloads

1,021

Version

1.0.4

License

MIT

Unpacked Size

6.71 kB

Total Files

6

Last publish

Collaborators

  • vsync