This fork added Typescript typing and num seconds ago
since-time-ago
since-time-ago converts timestamps into readable format
Formats a timestamp to:
- just now
- 3 minutes ago
- 5 hours ago
- 8 days ago
- 6 months ago
- 4 years ago
Install
$ npm i since-time-ago
Use
This module exports a main function 'since()' that takes one argument 'timestamp' and returns
timestamp formated in a readable form:
import since from "since-time-ago";
const minute = 60 * 1000;
const hour = 60 * minute;
const day = 24 * hour;
const month = 30 * day;
const year = 12 * month;
const nowTimestamp = new Date().getTime();
const fiveMinutesAgoTimestamp = nowTimestamp - 5 * minute;
const fiveHoursAgoTimestamp = nowTimestamp - 5 * hour;
const fiveDaysAgoTimestamp = nowTimestamp - 5 * day;
const fiveMonthsAgoTimestamp = nowTimestamp - 5 * month;
const fiveYearsAgoTimestamp = nowTimestamp - 5 * year;
since();
since("hello world");
since(nowTimestamp);
since(fiveMinutesAgoTimestamp);
since(fiveHoursAgoTimestamp);
since(fiveDaysAgoTimestamp);
since(fiveMonthsAgoTimestamp);
since(fiveYearsAgoTimestamp);
License
MIT