A lightweight JavaScript/Node.js library to format timestamps into human-readable relative time (e.g., "5 minutes ago", "2 hours ago", "Yesterday").
Install via npm:
npm install time-ago-formatter
Or via yarn:
yarn add time-ago-formatter
const timeAgo = require("time-ago-formatter");
console.log(timeAgo(Date.now() - 60000)); // "1 minute ago"
console.log(timeAgo(Date.now() - 3600000)); // "1 hour ago"
console.log(timeAgo(Date.now() - 86400000)); // "1 day ago"
console.log(timeAgo("2023-12-01")); // "2 months ago"
Formats a timestamp into a compact, human-readable relative time string.
Parameter | Type | Description |
---|---|---|
input |
Date / String / Number
|
The date or timestamp to format |
This package is licensed under the MIT License.
Contributions are welcome! Feel free to open an issue or submit a pull request.
Developed by Rohit Chavan.