J

JavaScript Handbook

Clean • Professional

JavaScript Date Get Methods

2 minute

JavaScript Date Get Methods

Date objects provide getter methods to retrieve different parts of a date. You can get the year, month, day, hours, minutes, seconds, milliseconds, and day of the week.

These methods come in local time and UTC variants.

learn code with durgesh images

getFullYear() – Get the Year

The getFullYear() method returns the four-digit year of a date object.

Example:

const d = new Date("2025-10-08T18:30:00");
console.log(d.getFullYear());
// 2025

getMonth() – Get the Month

getMonth() returns the month of the date, but months are 0-indexed, meaning January = 0 and December = 11.

Example:

const d = new Date("2025-10-08");
console.log(d.getMonth());
// 9 → October (0 = January)

getDate() – Get the Day of the Month

getDate() returns the day of the month (1–31).

const d = new Date("2025-10-08");
console.log(d.getDate());
// 8

getDay() – Get the Day of the Week

getDay() returns the day of the week as a number (0–6).

Example:

const d = new Date("2025-10-08");
console.log(d.getDay());
// 3 → Wednesday (0 = Sunday)

getHours() – Get Hours

getHours() returns the hour of the day (0–23) in local time.

Example:

const d = new Date("2025-10-08T18:30:00");
console.log(d.getHours());
// 18

getMinutes() – Get Minutes

getMinutes() returns minutes (0–59).

Example:

const d = new Date("2025-10-08T18:30:45");
console.log(d.getMinutes());
// 30

getSeconds() – Get Seconds

getSeconds() returns the seconds (0–59) of a date object.

Example:

const d = new Date("2025-10-08T18:30:45");
console.log(d.getSeconds());
// 45

getMilliseconds() – Get Milliseconds

getMilliseconds() returns milliseconds (0–999).

Example:

const d = new Date("2025-10-08T18:30:45.123");
console.log(d.getMilliseconds());
// 123

getTime() – Get Timestamp

getTime() returns the number of milliseconds since January 1, 1970, 00:00:00 UTC (Unix Epoch).

Example:

const d = new Date("2025-10-08T18:30:00");
console.log(d.getTime());
// 1759917000000

getTimezoneOffset() – Get Time Zone Difference

getTimezoneOffset() returns the difference in minutes between local time and UTC.

Example:

const d = new Date("2025-10-08T18:30:00");
console.log(d.getTimezoneOffset());
// -330 → IST is UTC+5:30

Summary Table – JavaScript Date Get Methods

MethodReturnsUTC VariantUse Case / Notes
getFullYear()4-digit yeargetUTCFullYear()Display year, calculate age
getMonth()Month (0–11)getUTCMonth()Month-based calculations, formatted display
getDate()Day of month (1–31)getUTCDate()User-friendly dates, due dates
getDay()Day of week (0–6)getUTCDay()Weekly schedules, calendar apps
getHours()Hours (0–23)getUTCHours()Event scheduling, reminders
getMinutes()Minutes (0–59)getUTCMinutes()Time formatting (HH:MM)
getSeconds()Seconds (0–59)getUTCSeconds()Timers, animations
getMilliseconds()Milliseconds (0–999)getUTCMilliseconds()High-precision timing
getTime()Milliseconds since EpochN/ATimestamp comparisons, calculations
getTimezoneOffset()Minutes offset from UTCN/ATime zone conversions

 

Article 0 of 0