JavaScript Date getMonth() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Month (0–11)

What You’ll Learn

getMonth() returns the month as a zero-based index from 0 to 11 in local time (January = 0). This guide covers syntax, five examples, month-name mapping, UTC comparisons, and the off-by-one pitfall every beginner hits.

01

Syntax

date.getMonth()

02

Range

0 – 11

03

Jan = 0

Zero-based

04

+1 rule

Human 1–12

05

Names

Array / locale

06

Validate

Invalid → NaN

Introduction

Filters, billing cycles, and “posted in March” labels need the month from a Date. The getMonth() method returns that value as an integer—but unlike calendar labels, JavaScript counts months from zero.

Combine it with getFullYear() and getDate() to build custom date strings, or use toLocaleDateString() when locale formatting is enough.

Understanding the getMonth() Method

Date.prototype.getMonth() is a zero-argument instance method. It never mutates the original Date—it only reads the month index according to local time rules.

The zero-based index matches the second argument of new Date(year, monthIndex, day). If you create new Date(2026, 2, 15), getMonth() returns 2 (March).

💡
Beginner Tip

Memory hook: getMonth() + 1 gives calendar month numbers (1–12). February is index 1, not 2.

📝 Syntax

JavaScript
dateObj.getMonth()

Parameters

  • None.

Return value

  • Integer 0–11 for a valid date in local time.
  • NaN if dateObj is an invalid Date.

Month index table

  • 0 — January
  • 1 — February
  • 2 — March
  • 3 — April
  • 4 — May
  • 5 — June
  • 6 — July
  • 7 — August
  • 8 — September
  • 9 — October
  • 10 — November
  • 11 — December

⚡ Quick Reference

GoalCode
Current month indexnew Date().getMonth()
Human month 1–12date.getMonth() + 1
Month from fixed datenew Date(2026, 1, 15).getMonth() → 1 (Feb)
UTC month indexdate.getUTCMonth()
Month name (locale)date.toLocaleString("en-US", { month: "long" })
Valid date check!Number.isNaN(date.getTime())

📋 getMonth() vs Similar Methods

These getters answer different calendar questions. Match the method to what your UI or filter needs.

getMonth()
0–11

Local month index

getUTCMonth()
UTC index

Timezone-safe read

getDate()
1–31

Day of month

getFullYear()
2026

Four-digit year

Examples Gallery

Open DevTools Console (F12) or use Try-it links. Fixed dates use new Date(year, monthIndex, day) so indexes stay predictable.

📚 Getting Started

Read the zero-based month index from a known date.

Example 1 — Get the Month Index from a Fixed Date

February 15, 2026 is month index 1—not 2.

JavaScript
const feb15 = new Date(2026, 1, 15);
const monthIndex = feb15.getMonth();

console.log(monthIndex); // 1 (February)
Try It Yourself

How It Works

The constructor’s second argument uses the same zero-based index as getMonth(). Index 1 always means February.

📈 Practical Patterns

Human numbers, names, validation, and comparisons.

Example 2 — Convert to Human Month Numbers (1–12)

Add one when you need the calendar month number people expect.

JavaScript
const date = new Date(2026, 1, 15);
const monthNumber = date.getMonth() + 1;

console.log("Calendar month:", monthNumber); // 2 (February)
Try It Yourself

How It Works

getMonth() is zero-based; human calendars are one-based. The + 1 adjustment is the most common conversion in real apps.

Example 3 — Map the Index to a Month Name

Turn the numeric index into a readable English label.

JavaScript
const MONTHS = [
  "January", "February", "March", "April",
  "May", "June", "July", "August",
  "September", "October", "November", "December"
];

const date = new Date(2026, 1, 15);
console.log("Month:", MONTHS[date.getMonth()]);
// Month: February
Try It Yourself

How It Works

Array index aligns with getMonth()—index 0 is January. For i18n, prefer Intl.DateTimeFormat or toLocaleDateString.

Example 4 — Validate Before Calling getMonth()

Guard against invalid Date objects that yield NaN.

JavaScript
function safeGetMonth(date) {
  if (!(date instanceof Date) || Number.isNaN(date.getTime())) {
    return null;
  }
  return date.getMonth();
}

console.log(safeGetMonth(new Date(2026, 1, 15)));     // 1
console.log(safeGetMonth(new Date("not-a-date")));     // null
Try It Yourself

How It Works

MONTHS[NaN] returns undefined silently. Validate first so filters and labels never show blank month names.

Example 5 — Check If Two Dates Share the Same Month

Compare month indexes and years together for same-month logic.

JavaScript
function isSameMonth(a, b) {
  return a.getFullYear() === b.getFullYear() &&
         a.getMonth() === b.getMonth();
}

const june10 = new Date(2026, 5, 10);
const june28 = new Date(2026, 5, 28);
const nov20 = new Date(2026, 10, 20);

console.log(isSameMonth(june10, june28)); // true
console.log(isSameMonth(june10, nov20));  // false
Try It Yourself

How It Works

Month alone is not enough across years—June 2025 and June 2026 both return index 5 but are different calendar months. Include getFullYear() when it matters.

🚀 Common Use Cases

  • Month filters — show records from “this month.”
  • Billing — detect month-end and renewal dates.
  • Seasonal UI — swap themes by month index.
  • Form defaults — pre-select month in date pickers.
  • Analytics — group events by calendar month.
  • Date labels — build “Feb 15, 2026” strings.

🧠 How getMonth() Resolves the Month

1

Internal instant

The Date stores milliseconds since Unix epoch (UTC).

Storage
2

Local conversion

Engine applies the runtime timezone offset.

TZ
3

Extract month

Zero-based index 0–11 is returned.

getMonth
4

Map or compare

Add 1, map to names, filter, or pass to setMonth.

📝 Notes

  • getMonth() is zero-based (January = 0).
  • Use getUTCMonth() when you standardize on UTC.
  • Invalid dates propagate NaN—validate first.
  • Compare with getFullYear() when month spans years matter.
  • setMonth(getMonth() + 1) adds one month with automatic year rollover.
  • For display, prefer locale formatters over hard-coded English arrays.

Browser & Runtime Support

Date.prototype.getMonth() has been available since the first JavaScript Date implementation (ES1). It works in every browser and Node.js.

Baseline · ES1

Date.prototype.getMonth()

Supported in Chrome, Firefox, Safari, Edge, Internet Explorer, and all Node.js versions. No polyfill required.

99% Universal API
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Date.getMonth() Excellent

Bottom line: Safe everywhere. Remember the zero-based index—February is 1, not 2.

Conclusion

getMonth() reads the local month as a zero-based index from 0 to 11. Add one for human calendar numbers, map to names for display, and always pair with getFullYear() when comparing months across years.

Next, learn getSeconds() for the second component, or setMonth() to write the month index directly.

💡 Best Practices

✅ Do

  • Remember January = 0 when reading getMonth()
  • Use getMonth() + 1 for calendar numbers 1–12
  • Validate dates before calling getMonth()
  • Include year when comparing same-month logic
  • Use locale formatters for month names in production

❌ Don’t

  • Assume February is index 2
  • Confuse getMonth() with getDate()
  • Ignore NaN from bad parses
  • Compare months without checking the year
  • Hard-code English names in multilingual apps

Key Takeaways

Knowledge Unlocked

Five things to remember about Date.getMonth()

Your foundation for month reads in JavaScript.

5
Core concepts
🔢 02

0–11

Jan = 0.

Range
🌐 03

Local

Not UTC.

Timezone
🔄 04

+1

Human 1–12.

Convert
05

Feb = 1

Not 2.

Pitfall

❓ Frequently Asked Questions

An integer from 0 to 11 representing the month in the Date object's local timezone. 0 is January, 1 is February, … 11 is December.
JavaScript follows the same zero-based month index as the Date constructor's second argument. Add 1 when you need human-readable month numbers 1–12.
getMonth() uses local timezone rules. getUTCMonth() reads the UTC month index. Near midnight on month boundaries they can differ.
NaN. Validate with !Number.isNaN(date.getTime()) before using the result.
Use date.toLocaleString('en-US', { month: 'long' }) for locale-aware names, or map getMonth() to an array of English month strings.
Yes. new Date(2026, 2, 15) creates March 15 and getMonth() returns 2—the same zero-based index you passed in.
Did you know?

The Date constructor and getMonth() share the same zero-based month index. If you pass 2 to new Date(2026, 2, 15), getMonth() returns 2 (March)—no conversion needed when building and reading the same date.

Continue to getSeconds()

Learn how to read the second component (0–59) from a Date object in local time.

getSeconds() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful