getters
Date.prototype.getMonth
Returns the month of the date in LOCAL time as an integer from 0 (January) to 11 (December). This zero-based indexing is the single most common source of off-by-one date bugs in JavaScript.
date.getMonth() Parameters
| Parameter | Purpose |
|---|---|
| () | no arguments; returns 0-11 |
| +1 | add 1 for a human month number (1-12) |
Examples
console.log(new Date('2026-07-19').getUTCMonth()); // 6 July is 6, not 7
console.log(new Date('2026-01-01').getUTCMonth()); // 0 January = 0
const m = new Date().getMonth() + 1; console.log(m); // human 1-12 convert to 1-based
const names=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; console.log(names[new Date('2026-07-19').getUTCMonth()]); // 'Jul' index into a month array
Gotcha
getMonth returns 0-11, NOT 1-12 (January=0, December=11). Always add 1 before displaying a human month number.
Related
Date.prototype.getFullYear
Returns the 4-digit year of the date according to LOCAL time. Prefer this over the deprecated getYear(), which returns year-1900.
Date.prototype.getDate
Returns the day of the month (1-31) in LOCAL time. Do not confuse this with getDay, which returns the weekday.
Date.prototype.getDay
Returns the weekday of the date in LOCAL time as an integer from 0 (Sunday) to 6 (Saturday). Named confusingly close to getDate but returns something completely different.
Date.prototype.getHours
Returns the hour of the date in LOCAL time as an integer from 0 to 23. Companion methods getMinutes, getSeconds, and getMilliseconds work the same way for their respective units.
Date.prototype.getMinutes
Returns the minutes portion of the date in LOCAL time as an integer from 0 to 59. The identically shaped getSeconds (0-59) and getMilliseconds (0-999) round out the sub-hour getters.