fdu logo@pyyupsk/fdu - Faster Date-Time Utility
API Reference

Get

Master date getter methods to extract individual components from date instances. Learn how to get year, month, day, hour, minute, second, and millisecond values with practical examples for checking weekends, validating dates, building time objects, and implementing common date patterns.

Getter methods allow you to extract individual components from a date instance.

year()

Gets the 4-digit year value.

.year(): number

Example

import { fdu } from "@pyyupsk/fdu";

const date = fdu("2024-01-15");
date.year(); // 2024

month()

Gets the month value (0-11, where 0 = January).

.month(): number

Months are zero-indexed like JavaScript's native Date object. January is 0, February is 1, etc.

Example

const date = fdu("2024-01-15");
date.month(); // 0 (January)

const date2 = fdu("2024-12-25");
date2.month(); // 11 (December)

date()

Gets the day of the month (1-31).

.date(): number

Example

const date = fdu("2024-01-15");
date.date(); // 15

const date2 = fdu("2024-01-01");
date2.date(); // 1

day()

Gets or sets the day of the week (0-6, where 0 = Sunday).

.day(): number
.day(value: number): FduInstance

The day() method can also be used as a setter. See day() setter for manipulation examples.

Example (Getter)

const date = fdu("2024-01-15"); // Monday
date.day(); // 1

const sunday = fdu("2024-01-14");
sunday.day(); // 0

const saturday = fdu("2024-01-20");
saturday.day(); // 6

Day Values

ValueDay
0Sunday
1Monday
2Tuesday
3Wednesday
4Thursday
5Friday
6Saturday

weekday()

Gets or sets the locale-aware day of the week (0-6, where 0 = first day of week in current locale).

.weekday(): number
.weekday(value: number): FduInstance

Unlike day(), weekday() respects the locale's week start setting. The weekday() method can also be used as a setter. See weekday() setter for manipulation examples.

Example (Getter)

const date = fdu("2025-10-05").locale("en"); // Sunday

// English locale has weekStart: 0 (Sunday)
date.weekday(); // 0 (Sunday is first day of week)

const monday = fdu("2025-10-06").locale("en"); // Monday
monday.weekday(); // 1 (Monday is second day of week)

Locale Comparison

// English locale (weekStart: 0 - Sunday)
const dateEn = fdu("2025-10-05").locale("en"); // Sunday
dateEn.day(); // 0 (Sunday)
dateEn.weekday(); // 0 (first day of week)

// Custom locale with Monday start (weekStart: 1)
registerLocale("custom", { ...en, weekStart: 1 });
const dateCustom = fdu("2025-10-05").locale("custom"); // Sunday
dateCustom.day(); // 0 (Sunday)
dateCustom.weekday(); // 6 (last day of week in Monday-start locale)

hour()

Gets the hour in 24-hour format (0-23).

.hour(): number

Example

const date = fdu("2024-01-15T14:30:00");
date.hour(); // 14

const midnight = fdu("2024-01-15T00:00:00");
midnight.hour(); // 0

const noon = fdu("2024-01-15T12:00:00");
noon.hour(); // 12

minute()

Gets the minutes (0-59).

.minute(): number

Example

const date = fdu("2024-01-15T14:30:00");
date.minute(); // 30

const date2 = fdu("2024-01-15T14:05:00");
date2.minute(); // 5

second()

Gets the seconds (0-59).

.second(): number

Example

const date = fdu("2024-01-15T14:30:45");
date.second(); // 45

const date2 = fdu("2024-01-15T14:30:08");
date2.second(); // 8

millisecond()

Gets the milliseconds (0-999).

.millisecond(): number

Example

const date = fdu("2024-01-15T14:30:45.123");
date.millisecond(); // 123

const date2 = fdu("2024-01-15T14:30:45.005");
date2.millisecond(); // 5

Complete Example

import { fdu } from "@pyyupsk/fdu";

const date = fdu("2024-01-15T14:30:45.123");

console.log(date.year()); // 2024
console.log(date.month()); // 0 (January)
console.log(date.date()); // 15
console.log(date.day()); // 1 (Monday, 0=Sunday)
console.log(date.hour()); // 14
console.log(date.minute()); // 30
console.log(date.second()); // 45
console.log(date.millisecond()); // 123

Common Patterns

Check if weekend

const date = fdu("2024-01-15");
const day = date.day();
const isWeekend = day === 0 || day === 6; // Sunday or Saturday

Check if specific day of week

const date = fdu("2024-01-15");
const isMonday = date.day() === 1;
const isFriday = date.day() === 5;

Check if morning/afternoon/evening

const date = fdu("2024-01-15T14:30:00");
const hour = date.hour();

const isMorning = hour >= 6 && hour < 12;
const isAfternoon = hour >= 12 && hour < 18;
const isEvening = hour >= 18 && hour < 22;
const isNight = hour >= 22 || hour < 6;

Check if specific month

const date = fdu("2024-12-25");
const isDecember = date.month() === 11; // Remember: 0-indexed!
const isJanuary = date.month() === 0;

Extract time components

const date = fdu("2024-01-15T14:30:45.123");

const timeObj = {
  hours: date.hour(),
  minutes: date.minute(),
  seconds: date.second(),
  milliseconds: date.millisecond(),
};
// { hours: 14, minutes: 30, seconds: 45, milliseconds: 123 }

Build date object

const date = fdu("2024-01-15T14:30:45");

const dateObj = {
  year: date.year(),
  month: date.month() + 1, // Convert to 1-12
  day: date.date(),
  dayOfWeek: date.day(),
  hour: date.hour(),
  minute: date.minute(),
  second: date.second(),
};

See Also

On this page