Get the current year in JavaScript

Create a new Date() object and call getFullYear():

new Date().getFullYear()  // returns the current year

Example usage: a page footer that always shows the current year:

document.getElementById("year").innerHTML = new Date().getFullYear();
footer {
  text-align: center;
  font-family: sans-serif;
    ©<span id="year"></span> by Donald Duck

See also, the Date() constructor’s full list of methods.

Leave a Comment