time-ago-formatter

1.0.0 • Public • Published

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-formatter

Or via yarn:

yarn add time-ago-formatter

Usage

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.

Package Sidebar

Install

npm i time-ago-formatter

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

2.61 kB

Total Files

4

Last publish

Collaborators

  • rc_npmjs