@s1vann/dateformat
v0.0.2
Published
Modern Date Formatting, Relative Time, Durations, Timezones, Countdowns, Templates and Date Utilities
Maintainers
Readme
📅 @s1vann/dateformat
Modern Date Formatting, Relative Time, Durations, Timezones, Countdowns, Templates and Date Utilities for Node.js.
Fast • Lightweight • Zero Dependencies • Modern API
✨ Features
- 📅 Date Formatting
- 🕒 Relative Time
- ⏳ Duration Formatting
- 🚀 Countdown Utilities
- 🌍 Timezone Formatting
- ➕ Add Date Units
- ➖ Subtract Date Units
- 📊 Date Difference Calculator
- ✅ Date Validation
- 🎨 Template Engine
- ⚡ Zero Dependencies
- 🔥 CommonJS Support
- 🌳 Lightweight
- 🚀 Node.js Optimized
📦 Installation
npm install @s1vann/dateformatyarn add @s1vann/dateformatpnpm add @s1vann/dateformat🚀 Quick Start
const {
format,
fromNow,
duration,
countdown,
tz,
add,
subtract,
diff,
isValid,
isLeapYear,
template
} = require('@s1vann/dateformat');📅 Date Formatting
Basic Format
format(new Date(), 'YYYY-MM-DD');Output:
2026-06-02Full Date
format(
new Date(),
'dddd, MMMM D, YYYY'
);Output:
Tuesday, June 2, 2026Time Format
format(
new Date(),
'HH:mm:ss'
);Output:
16:35:20🎯 Supported Tokens
| Token | Example | |---------|---------| | YYYY | 2026 | | YY | 26 | | MMMM | June | | MM | 06 | | M | 6 | | DD | 02 | | D | 2 | | dddd | Tuesday | | HH | 16 | | mm | 35 | | ss | 20 |
🕒 Relative Time
Past Dates
fromNow(
Date.now() - 1000 * 60 * 5
);Output:
5 minutes agoFuture Dates
fromNow(
Date.now() + 1000 * 60 * 60
);Output:
in 1 hour⏳ Duration Formatting
Convert milliseconds into readable durations.
duration(93784000);Output:
1 day 2 hours 3 minutes 4 seconds🚀 Countdown
Calculate remaining time until a future date.
countdown('2027-01-01');Output:
{
days: 212,
hours: 12,
minutes: 18,
seconds: 42
}🌍 Timezones
Format dates in any supported IANA timezone.
tz(
new Date(),
'Asia/Baghdad'
);Output:
Tuesday, June 2, 2026 at 4:35:20 PM GMT+3More Examples
tz(new Date(), 'America/New_York');
tz(new Date(), 'Europe/London');
tz(new Date(), 'Asia/Tokyo');➕ Add Time
Add units to a date.
add(
new Date(),
7,
'days'
);Output:
2026-06-09T...Supported Units
seconds
minutes
hours
days
months
years➖ Subtract Time
subtract(
new Date(),
30,
'days'
);Output:
2026-05-03T...📊 Date Difference
diff(
'2026-01-01',
'2026-06-01'
);Output:
{
days: 151,
hours: 3624,
minutes: 217440,
seconds: 13046400
}✅ Date Validation
Check Valid Date
isValid('2026-06-02');Output:
trueisValid('2026-02-30');Output:
false🏆 Leap Year Detection
isLeapYear(2028);Output:
trueisLeapYear(2027);Output:
false🎨 Template Engine
Create custom text templates.
template(
'Hello {name}',
{
name: 'S1VANN'
}
);Output:
Hello S1VANNDate Template Example
template(
'Today is {day}',
{
day: format(
new Date(),
'dddd'
)
}
);Output:
Today is Tuesday🔥 Real World Example
const {
format,
fromNow,
countdown
} = require('@s1vann/dateformat');
console.log(
format(
new Date(),
'dddd, MMMM D YYYY'
)
);
console.log(
fromNow(
Date.now() - 600000
)
);
console.log(
countdown(
'2027-01-01'
)
);Output:
Tuesday, June 2 2026
10 minutes ago
{
days: 212,
hours: 12,
minutes: 18,
seconds: 42
}📋 API
format()
format(date, pattern)Formats a date using custom tokens.
fromNow()
fromNow(date)Returns human readable relative time.
duration()
duration(milliseconds)Converts milliseconds into a readable duration.
countdown()
countdown(targetDate)Returns remaining time until target date.
tz()
tz(date, timezone)Formats a date using a specific timezone.
add()
add(date, amount, unit)Adds time to a date.
subtract()
subtract(date, amount, unit)Subtracts time from a date.
diff()
diff(start, end)Calculates date difference.
isValid()
isValid(date)Checks if a date is valid.
isLeapYear()
isLeapYear(year)Checks if a year is leap year.
template()
template(string, values)Replaces placeholders with values.
⚡ Why @s1vann/dateformat?
| Feature | Supported | |----------|------------| | Date Formatting | ✅ | | Relative Time | ✅ | | Duration Formatting | ✅ | | Countdown | ✅ | | Timezones | ✅ | | Add / Subtract | ✅ | | Date Difference | ✅ | | Validation | ✅ | | Template Engine | ✅ | | Zero Dependencies | ✅ | | CommonJS | ✅ | | Lightweight | ✅ |
📄 License
MIT License © S1VANN
Made with ❤️ by S1VANN
