An utility library for time and date manipulation
npm install timexjsA 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.
---
You can install TimeX using npm or yarn:
``bash`
npm install timex
`bash`
yarn add timex
---
`javascript
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"
`
---
* Format dates (formatDate)isLeapYear
* Get day & month names (long and short)
* ISO, UTC, and Unix timestamp conversion
* Leap year detection ()getTimeOfDay
* Time of day detection ()getAgeFromDateOfBirth
* Age calculation ()isToday
* Relative date checks (, isYesterday, isTomorrow)isWeekday
* Weekday/weekend checks (, isWeekend)isSameDay
* Compare two dates ()getTimeZone`)
* Timezone detection (
---
MIT License