1.0.10 • Published 3 years ago
relative-time-ago v1.0.10
relative-time-ago
relativeTimeAgo(date, key);Returns a specified amount of time since a specified date.
Installation
npm install relative-time-agoUsage
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 agoIf the difference in time is less than the requested interval, a different message is returned:
console.log(relativeTimeAgo(dateLessThanAYearAgo, 'year');
---> // less than one year agoIf no key is given, the time since the given date is returned in milliseconds:
console.log(relativeTimeAgo(date);
---> // XXXXX milliseconds agoIf relativeTimeAgo is called without a date argument, check your console to see error.
Thanks for reading! Check out my portfolio at derekmason.dev