How to get the current year in JavaScript

Getting the current year is essential for dynamic copyright notices, age calculations, and year-based filtering in web applications. As the creator of CoreUI, a widely used open-source UI library, I’ve implemented current year functionality in numerous footer components, date pickers, and analytics dashboards. From my expertise, the most reliable and precise solution is to use the getFullYear() method on a Date object. This approach returns the complete 4-digit year and automatically updates as time progresses, making it perfect for dynamic content.

Use getFullYear() method to get the current year as a 4-digit number.

const currentYear = new Date().getFullYear()

The getFullYear() method returns the year as a complete 4-digit number (e.g., 2023, 2024) according to local time. This is different from the deprecated getYear() method which returned years relative to 1900. The method is timezone-aware and automatically reflects the user’s local calendar year. This makes it ideal for copyright notices like © ${new Date().getFullYear()} Company Name that update automatically each year without code changes.

Best Practice Note:

This is the same approach we use in CoreUI templates for dynamic copyright notices and year-based components. Avoid using getYear() which is deprecated and returns inconsistent values - always use getFullYear() for reliable year extraction.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
JavaScript printf equivalent
JavaScript printf equivalent

What are the three dots `...` in JavaScript do?
What are the three dots `...` in JavaScript do?

How to Merge Objects in JavaScript
How to Merge Objects in JavaScript

How to Get Unique Values from a JavaScript Array
How to Get Unique Values from a JavaScript Array

Answers by CoreUI Core Team