time-ago-formatter
v1.0.0
Published
A lightweight JavaScript library to format timestamps into human-readable relative time (e.g., '5 minutes ago').
Maintainers
Readme
time-ago-formatter
A lightweight JavaScript/Node.js library to format timestamps into human-readable relative time (e.g., "5 minutes ago", "2 hours ago", "Yesterday").
Installation
Install via npm:
npm install time-ago-formatterOr via yarn:
yarn add time-ago-formatterUsage
Import the Package
const timeAgo = require("time-ago-formatter");Basic Usage
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"API Reference
timeAgo(input)
Formats a timestamp into a compact, human-readable relative time string.
| Parameter | Type | Description |
|------------|--------|-------------|
| input | Date / String / Number | The date or timestamp to format |
License
This package is licensed under the MIT License.
Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request.
Author
Developed by Rohit Chavan.
