Quick Start
-
Install
Terminal window npm install date-wiz -
Import what you need
import { wiz, format, getRelativeTime, parse, smartFormat } from 'date-wiz'; -
Format a date
format(new Date(), 'DD MMMM YYYY') // "15 March 2026"format(new Date(), 'DD MMMM', 'bn-BD') // "১৫ মার্চ"format(new Date(), 'hh:mm A') // "02:30 PM"format(new Date(), 'LLL') // "March 15, 2026 at 2:30 PM" -
Get relative time
getRelativeTime(twoDaysAgo) // "2 days ago"getRelativeTime(twoDaysAgo, { precision: 2 }) // "2 days, 4 hours ago"getRelativeTime(nextWeek, { locale: 'fr' }) // "dans 7 jours" -
Use the chainable API
const deadline = wiz(new Date()).add(3, 'businessDays').setHour(17).format('LLL');// → "March 19, 2026 at 5:00 PM"
Common patterns
Section titled “Common patterns”Countdown timer
Section titled “Countdown timer”import { getRelativeTime } from 'date-wiz';
const launch = new Date('2026-12-31T00:00:00');console.log(getRelativeTime(launch));// → "in 9 months"Smart timestamps in a feed
Section titled “Smart timestamps in a feed”import { smartFormat } from 'date-wiz';
posts.map(post => ({ ...post, displayDate: smartFormat(post.createdAt), // → "Today at 9:42 AM" | "Yesterday at 3:00 PM" | "Oct 12, 2022"}));Business day deadline
Section titled “Business day deadline”import { addBusinessDays } from 'date-wiz';
const slaDeadline = addBusinessDays(new Date(), 5, { holidays: ['2026-12-25', '2026-01-01'],});Parse a user-typed date
Section titled “Parse a user-typed date”import { parse, format } from 'date-wiz';
const d = parse(userInput); // "next_monday", "+2d", "15-05-2024" — all workif (d) { console.log(format(d, 'LL')); // "March 16, 2026"}