relative-time-ago
v1.0.10
Published
Return a specified unit of time since a given date.
Downloads
4
Readme
relative-time-ago
relativeTimeAgo(date, key);
Returns a specified amount of time since a specified date.
Installation
npm install relative-time-ago
Usage
import relativeTimeAgo from "relative-time-ago";
- Inputs -
date
- Either a date string or UNIX number.
key
- What you want your time intervals to be relevant to..
year
- returns number of years agomonth
- returns number of months agoday
- returns number of days agohour
- returns number of hours agominute
- returns number of minutes agosecond
- returns number of seconds ago
- Outputs -
By default will return the number of milliseconds between the given date and whenever relativeTimeAgo
is called.
Alternatively, if given a key, will return a message:
console.log(relativeTimeAgo(date, 'second');
---> // X seconds ago
If the difference in time is less than the requested interval, a different message is returned:
console.log(relativeTimeAgo(dateLessThanAYearAgo, 'year');
---> // less than one year ago
If no key is given, the time since the given date is returned in milliseconds:
console.log(relativeTimeAgo(date);
---> // XXXXX milliseconds ago
If relativeTimeAgo is called without a date argument, check your console to see error.
Thanks for reading! Check out my portfolio at derekmason.dev