JSPM

@souravdey/time-ago

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q13453F
  • License MIT

get the time difference with current time with a simple function

Package Exports

  • @souravdey/time-ago

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@souravdey/time-ago) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

🕒time-ago

Get the time difference with current time as string with a simple npm package.

Installation

npm install @souravdey/time-ago

Usage

import getTimeAgoString from '@souravdey/time-ago';

var timeAgo = getTimeAgoString(unixtimestamp);
var timeAgoAbbreviation = getTimeAgoString(unixtimestamp,true);

console.log(timeAgo) // output eg. 21 minutes
console.log(timeAgoAbbreviation) // output eg. 21 mins

params for the function

  • unixtimestamp in miliseconds eg. 1617799359000
  • abbreviation as true or false. It is not a mandatory feild and default value is false. If passed true it will abbreviate the units eg. minutes to mins.

getTimeAgoString function returns a string as per the time diffrence of the current time.

  • x seconds/secs if the diffrence between current time and unix timestamp is within 59 secs.

  • x minutes/mins if the diffrence between current time and unix timestamp is within 1 min to 59 mins.

  • x hours/hrs if the diffrence between current time and unix timestamp is within 1 hr to 23 hrs.

  • x days/ds if the diffrence between current time and unix timestamp is within 1 day to 30 days.

  • x months/mths if the diffrence between current time and unix timestamp is within 1 month to 11 months.

  • x years/yrs if the diffrence between current time and unix timestamp is more than 1 year.