time-left-ago
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

time-left-ago

Provide time left and time ago

Install

yarn add time-left-ago

Example

timeLeft returns the specified time that left until the provided ttl in seconds, minutes, hours or days.

import { timeLeft } from 'time-left-ago'

const ttl = 40/60
const timeString = timeLeft(new Date(), ttl)
// => 40 seconds left

timeAgo returns the specified date that passed since the provided timestamp in time, day or date.

import { timeAgo } from 'time-left-ago'
import moment from 'moment'

const today = moment() // Sunday
const dayBeforeYesterday = today.subtract(2, 'days')
const dayString = timeAgo(dayBeforeYesterday)
// => Friday

timeAgoFormatted returns the specified date bucketed by minutes, hours or days.

import { timeAgoFormatted } from 'time-left-ago'

const twoDaysAgo = moment(Date.now()).subtract(2, 'days').toString()
const formatted = timeAgoFormatted(twoDaysAgo) // => '2 DAYS'

const twoHoursAgo = moment(Date.now()).subtract(2, 'hours').toString()
const formatted = timeAgoFormatted(twoHoursAgo) // => '2 HOURS'

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i time-left-ago

Weekly Downloads

185

Version

2.0.2

License

MIT

Unpacked Size

18.2 kB

Total Files

23

Last publish

Collaborators

  • taliisraeli