JS Built-ins
← Date26 / 120
DategetMonthbeginner

getMonth() β€” January is 0

πŸ“– Usage Example
const d = new Date(2024, 5, 15)  // June
d.getMonth()  // β†’ 5
// 0=Jan, 11=Dec

Use getMonth() to retrieve the zero-indexed month (0 = January through 11 = December) of a Date in local time.

Date.prototype.getMonth()

Returns the month index (0 = January, 11 = December) in local time.

Challenge: Verify that new Date(2024, 0, 15).getMonth() returns 0 (January).

πŸ’‘ Hints (1)
  • β€’ Month indexing starts at 0: January=0, February=1, …, December=11