JavaScript Date getFullYear() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Four-digit year

What You’ll Learn

getFullYear() returns the four-digit calendar year (e.g. 2026) from a Date object in local time. This guide covers syntax, five examples, UTC comparisons, validation, and common real-world patterns like copyright footers.

01

Syntax

date.getFullYear()

02

Format

4-digit year

03

Local time

Not UTC

04

vs getYear

Deprecated

05

Footer

Copyright year

06

Validate

Invalid → NaN

Introduction

Copyright notices, age displays, fiscal-year filters, and “posted in 2026” labels all need the year component from a Date. The getFullYear() method returns that value as a plain integer using the user’s local timezone.

Pair it with getMonth() and getDate() to build custom formats, or use getUTCFullYear() when your app standardizes on UTC.

Understanding the getFullYear() Method

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

Unlike the deprecated getYear() (which returned year - 1900), getFullYear() always gives you the complete four-digit year, which is what humans expect in UI copy and logs.

💡
Beginner Tip

Need the year in a string? String(date.getFullYear()) works, but for full dates prefer toLocaleDateString() or Intl.DateTimeFormat.

📝 Syntax

JavaScript
dateObj.getFullYear()

Parameters

  • None.

Return value

  • Integer four-digit year (e.g. 2026) for a valid date in local time.
  • NaN if dateObj is an invalid Date.

⚡ Quick Reference

GoalCode
Current yearnew Date().getFullYear()
Year from fixed datenew Date(2026, 6, 4).getFullYear() → 2026
UTC yeardate.getUTCFullYear()
Copyright footerel.textContent = new Date().getFullYear()
Set yeardate.setFullYear(2027)
Valid date check!Number.isNaN(date.getTime())

📋 getFullYear() vs Similar Methods

Pick the getter that matches your timezone strategy and the format you need to display.

getFullYear()
2026

Local 4-digit year

getUTCFullYear()
UTC year

Timezone-safe read

getYear() ⚠
126

Deprecated; avoid

getMonth()
0–11

Zero-based month

Examples Gallery

Open DevTools Console (F12) or use Try-it links. Fixed dates use new Date(year, monthIndex, day) to avoid string parsing surprises.

📚 Getting Started

Read the year from the current date.

Example 1 — Get the Current Year

Call getFullYear() on a new Date() to read today’s calendar year.

JavaScript
const currentDate = new Date();
const currentYear = currentDate.getFullYear();

console.log("Current year:", currentYear);
Try It Yourself

How It Works

new Date() captures “now.” getFullYear() extracts only the year integer in local time—hours and minutes are ignored for this getter.

📈 Practical Patterns

Fixed dates, validation, DOM updates, and age logic.

Example 2 — Read the Year from a Specific Date

Build a date with numeric parts and confirm the year component.

JavaScript
const july4 = new Date(2026, 6, 4);

console.log(july4.getFullYear());  // 2026
console.log(july4.getMonth());     // 6 (July)
console.log(july4.getDate());      // 4
Try It Yourself

How It Works

The constructor uses zero-based months (6 = July). getFullYear() returns the year you passed in when the date is valid.

Example 3 — Validate Before Calling getFullYear()

Guard against invalid Date objects that yield NaN.

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

console.log(safeGetFullYear(new Date()));              // e.g. 2026
console.log(safeGetFullYear(new Date("not-a-date")));  // null
Try It Yourself

How It Works

getTime() returns NaN on invalid dates. Checking first prevents displaying “Copyright NaN” in a footer or bad math in age calculations.

Example 5 — Approximate Age from a Birth Year

Subtract birth year from the current year, then adjust if the birthday has not occurred yet this year.

JavaScript
function calculateAge(birthDate) {
  const today = new Date();
  let age = today.getFullYear() - birthDate.getFullYear();

  const birthdayPassed =
    today.getMonth() > birthDate.getMonth() ||
    (today.getMonth() === birthDate.getMonth() &&
      today.getDate() >= birthDate.getDate());

  if (!birthdayPassed) {
    age -= 1;
  }
  return age;
}

const birthDate = new Date(1990, 4, 15); // May 15, 1990
console.log("Age:", calculateAge(birthDate), "years");
Try It Yourself

How It Works

Year subtraction alone is not enough—someone born May 15 is still one year younger on January 1. Combining getFullYear(), getMonth(), and getDate() fixes that edge case.

🚀 Common Use Cases

  • Copyright footers — auto-update the year in site footers.
  • Age gates — compare birth year against a minimum age rule.
  • Year filters — “show posts from 2025” in dashboards.
  • Invoice headers — fiscal year labels on PDFs.
  • Form defaults — pre-select year in date pickers.
  • Analytics buckets — group events by calendar year.

🧠 How getFullYear() Resolves the Year

1

Internal instant

The Date stores milliseconds since Unix epoch (UTC).

Storage
2

Local conversion

Engine applies the runtime timezone offset.

TZ
3

Extract year

Four-digit calendar year is returned as an integer.

getFullYear
4

Use in UI

Display, filter, compare, or pass to setFullYear.

📝 Notes

  • getFullYear() is local; use getUTCFullYear() when you standardize on UTC.
  • Never use deprecated getYear()—it returns year - 1900.
  • Invalid dates propagate NaN—validate first.
  • Near midnight on Dec 31 / Jan 1, local year can differ from UTC year on the same instant.
  • Age from year subtraction alone is approximate; include month and day for accuracy.
  • Store the year in a variable if you use it multiple times in the same function for readability.

Browser & Runtime Support

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

Baseline · ES1

Date.prototype.getFullYear()

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.getFullYear() Excellent

Bottom line: Safe everywhere. Watch timezone boundaries when pairing with UTC getters or ISO strings parsed from servers.

Conclusion

getFullYear() is the standard way to read the four-digit calendar year from a JavaScript Date in local time. Use it for footers, filters, and date math—and pair it with month/day getters when precision matters.

Next, learn getHours() for the hour component, or getUTCFullYear() for UTC year reads.

💡 Best Practices

✅ Do

  • Use getFullYear() instead of deprecated getYear()
  • Validate dates before calling getFullYear()
  • Pick UTC getters when storing UTC midnight
  • Include month/day for exact age calculations
  • Use locale formatters for full date display strings

❌ Don’t

  • Use getYear() in new code
  • Assume year subtraction alone gives exact age
  • Ignore NaN from bad parses
  • Mix UTC ISO strings with local getters blindly
  • Hard-code the copyright year in HTML

Key Takeaways

Knowledge Unlocked

Five things to remember about Date.getFullYear()

Your foundation for year reads in JavaScript.

5
Core concepts
🔢 02

4 digits

e.g. 2026.

Format
🌐 03

Local

Not UTC.

Timezone
© 04

Footer

Auto copyright.

Pattern
05

Not getYear

Deprecated.

Pitfall

❓ Frequently Asked Questions

A four-digit integer year (e.g. 2026) according to the Date object's local timezone. It always returns the full year—not a two-digit value.
getFullYear() uses local timezone rules. getUTCFullYear() reads the UTC calendar year. Near midnight on New Year's Eve they can differ by one year.
No. getYear() is deprecated and returned year minus 1900 (e.g. 126 for 2026). Always use getFullYear() for the four-digit year.
NaN. Validate with !Number.isNaN(date.getTime()) before using the result in UI or calculations.
No. Unlike the old getYear() method, getFullYear() always returns the complete four-digit year, including years before 1000 and after 9999.
document.getElementById('year').textContent = new Date().getFullYear(); This updates automatically each January without manual edits.
Did you know?

The old getYear() method returned 2026 - 1900 = 126 for the year 2026. That two-digit-style offset caused Y2K-era bugs—which is why getFullYear() replaced it as the standard.

Continue to getHours()

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

getHours() 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