date-npm
v1.1.0
Published
it is a date and time utilities package where u can change date and time in many diffrent times
Downloads
6
Readme
Date Formatter
A lightweight and flexible date formatting library for JavaScript.
Installation
npm i date-npm
import { formatDate, formatTimeAgo } from 'date-npm';
// Format current date
console.log(formatDate()); // e.g., "September 2 2024, 5:44:28 PM"
// Format specific date
console.log(formatDate(new Date('2024-09-02T14:30:00'))); // "September 2 2024, 2:30:00 PM"
// Format with different patterns
console.log(formatDate(new Date(), 'day')); // e.g., "Monday"
console.log(formatDate(new Date(), 'shortDefault')); // e.g., "Sep 2 24"
// Format time ago
console.log(formatTimeAgo(new Date(Date.now() - 5 * 60 * 1000))); // "5 minutes ago"
console.log(formatTimeAgo(new Date(Date.now() + 3 * 60 * 60 * 1000))); // "3 hours from now"
API
formatDate(date, format) Formats a date according to the specified format.
-date (optional): A Date object. Defaults to the current date if not provided. -format (optional): A string specifying the format. Can be 'day', 'shortDefault', or 'default' (default). formatTimeAgo(date) Returns a human-readable string representing the time difference between the given date and now.
-date: A Date object to compare with the current time.
Features
Flexible date formatting. -Human-readable time ago strings -Supports past and future dates -Handles various time units (seconds, minutes, hours, days, months, years)