timexjs
v1.0.0
Published
An utility library for time and date manipulation
Downloads
83
Readme
🕒 TimeX
A lightweight JavaScript utility library for date and time manipulation.
TimeX provides a collection of simple and powerful functions to format dates, get day/month names, calculate age, check weekdays/weekends, handle timezones, and more. Perfect for modern JavaScript projects.
📦 Installation
You can install TimeX using npm or yarn:
Using npm
npm install timexUsing yarn
yarn add timex⚡ Usage
import TimeX, {
formatDate,
getDayName,
getShortDayName,
getMonthName,
getShortMonthName,
toISO,
toUTC,
toUnix,
isLeapYear,
getTimeOfDay,
getAgeFromDateOfBirth,
isToday,
isYesterday,
isTomorrow,
isWeekend,
isWeekday,
isSameDay,
getTimeZone
} from 'timex';
// Formatting Dates
console.log(formatDate(new Date(), "DD/MM/YYYY")); // "04/12/2025"
// Day and Month Names
console.log(getDayName(new Date())); // "Thursday"
console.log(getShortDayName(new Date())); // "Thu"
console.log(getMonthName(new Date())); // "December"
console.log(getShortMonthName(new Date())); // "Dec"
// Convert Dates
console.log(toISO(new Date())); // "2025-12-04T12:30:00.000Z"
console.log(toUTC(new Date())); // { year: 2025, month: 12, day: 4, hour: 12, minute: 30, second: 0, iso: "2025-12-04T12:30:00.000Z" }
console.log(toUnix(new Date())); // 1730675400
// Leap Year Check
console.log(isLeapYear(2024)); // true
console.log(isLeapYear(1900)); // false
console.log(isLeapYear(2000)); // true
// Time of Day
console.log(getTimeOfDay(new Date())); // "afternoon"
// Age Calculation
console.log(getAgeFromDateOfBirth("1990-05-15")); // 35
// Relative Date Checks
console.log(isToday(new Date())); // true
console.log(isYesterday("2025-12-03")); // true
console.log(isTomorrow("2025-12-05")); // true
// Weekday / Weekend Checks
console.log(isWeekend(new Date())); // false
console.log(isWeekday(new Date())); // true
// Compare Two Dates
console.log(isSameDay("2025-12-04", new Date())); // true
// Get Timezone
console.log(getTimeZone()); // "Asia/Kolkata"✅ Features
- Format dates (
formatDate) - Get day & month names (long and short)
- ISO, UTC, and Unix timestamp conversion
- Leap year detection (
isLeapYear) - Time of day detection (
getTimeOfDay) - Age calculation (
getAgeFromDateOfBirth) - Relative date checks (
isToday,isYesterday,isTomorrow) - Weekday/weekend checks (
isWeekday,isWeekend) - Compare two dates (
isSameDay) - Timezone detection (
getTimeZone)
🔗 License
MIT License
