Chronify is a Node.js package that provides a simple way to calculate and display human-readable time differences between dates. Perfect for applications that need to show elapsed or remaining time in a user-friendly format.
- Flexible Time Units: Shows time differences in years, months, days, hours, and minutes.
- Customizable Output: Supports both full and abbreviated unit formats.
- Human-readable Format: Easy-to-understand phrases like "2 weeks ago" or "in 3 days."
Install Chronify via npm:
npm install chronifyImport and use Chronify in your Node.js project:
const { chronify } = require("chronify");Display the time difference from the current date:
console.log(chronify("2024-09-01T12:00:00Z"));
// Example Output: "2 weeks ago" (depending on the current date)Control the number of units displayed and use abbreviated formats:
console.log(chronify("2024-09-01T12:00:00Z", { maxUnits: 1, short: true }));
// Example Output: "2w ago" (depending on the current date)maxUnits(number): Maximum number of time units to display. Defaults to2.short(boolean): Use abbreviated units iftrue. Defaults tofalse.