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;
}
<footer>
<span id="year"></span> by Stack Overflow
</footer>
See also, the Date() constructor's full list of methods.
Top answer 1 of 13
2732
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;
}
<footer>
<span id="year"></span> by Stack Overflow
</footer>
See also, the Date() constructor's full list of methods.
2 of 13
316
// Return today's date and time
var currentTime = new Date()
// returns the month (from 0 to 11)
var month = currentTime.getMonth() + 1
// returns the day of the month (from 1 to 31)
var day = currentTime.getDate()
// returns the year (four digits)
var year = currentTime.getFullYear()
// write output MM/dd/yyyy
document.write(month + "/" + day + "/" + year)
W3Schools
w3schools.com › jsref › jsref_getfullyear.asp
JavaScript Date getFullYear() Method
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
How to get the current year in JavaScript? - TestMu AI Community
How to get the current year in JavaScript More on community.testmuai.com
JavaScript Date(Date)
Your code breaks if it's the first day of the month. And yeah, the built-in JavaScript date type is pretty garbage. I recommend using moment.js instead. More on reddit.com
Is there a way to insert the current year with HTML only?
no. html has no logic. if you are using a templated system in your email send, there should be some function or template tag that can insert it - you (probably) dynamically insert names and other personalization... More on reddit.com
Get url of current tab from firefox webextension!
You can also write it like this: function buttonClicked() { // query tabs to get current tab browser.tabs.query({currentWindow: true, active:true}).then(queryInfo => { browser.tabs.get(queryInfo[0].id).then(tab => { var tabUrl = tab.url; doSomething(taburl); browser.tabs.update(tab.id, {url: updUrl}); }); }); } More on reddit.com
Videos
Get the current year in JavaScript - Stack Overflow - YouTube
05:02
How to Get Current Date & Time in JavaScript | Date Object Tutorial ...
01:40
How to easily Get the Current Date and Year using JavaScript - YouTube
02:43
How To Get The Current Date With JavaScript - YouTube
03:36
Use JavaScript to Display the Current Year for a Copyright Paragraph ...
07:12
Use JavaScript to Display the Current Year for a Copyright Notice ...
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getYear
Date.prototype.getYear() - JavaScript | MDN
July 10, 2025 - The getYear() method of Date instances returns the year for this date according to local time.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getFullYear
Date.prototype.getFullYear() - JavaScript | MDN
July 10, 2025 - const moonLanding = new Date("July 20, 69 00:20:18"); console.log(moonLanding.getFullYear()); // Expected output: 1969 ... An integer representing the year for the given date according to local time.
DEV Community
dev.to › theudemezue › how-to-get-current-year-in-javascript-49f2
How To Get Current Year In JavaScript - DEV Community
March 8, 2025 - According to MDN Web Docs, the Date object in JavaScript is built specifically to handle dates and times. This makes it a natural choice for extracting information like the current year. By taking advantage of this built-in feature, I ensure that my code stays clean and efficient. At the core of getting the current year in JavaScript is the Date object.
Codemia
codemia.io › knowledge-hub › path › get_the_current_year_in_javascript
Get the current year in JavaScript
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › Date
Date() constructor - JavaScript | MDN
When called as a function, it returns a string representing the current time. const date1 = new Date("December 17, 1995 03:24:00"); // Sun Dec 17 1995 03:24:00 GMT... const date2 = new Date("1995-12-17T03:24:00"); // Sun Dec 17 1995 03:24:00 GMT... console.log(date1.getTime() === date2.getTime()); // Expected output: true ... new Date() new Date(value) new Date(dateString) new Date(dateObject) new Date(year, monthIndex) new Date(year, monthIndex, day) new Date(year, monthIndex, day, hours) new Date(year, monthIndex, day, hours, minutes) new Date(year, monthIndex, day, hours, minutes, seconds) new Date(year, monthIndex, day, hours, minutes, seconds, milliseconds) Date()
W3Schools
w3schools.com › js › js_date_methods.asp
JavaScript Get Date Methods
The getFullYear() method returns the year of a date as a four digit number: const d = new Date("2021-03-25"); d.getFullYear(); Try it Yourself » · const d = new Date(); d.getFullYear(); Try it Yourself » · Old JavaScript code might use the ...
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
Returns the year (usually 2–3 digits) in the specified date according to local time. Use getFullYear() instead.
Futurestud.io
futurestud.io › tutorials › get-the-current-year-in-javascript-or-node-js
Get the Current Year in JavaScript or Node.js
June 16, 2022 - The JavaScript engine comes with a global Date class. Interacting with dates is an essential part of programming. JavaScript’s Date comes with two methods to retrieve the current year: Date#getYear and Date#getFullYear.
Scaler
scaler.com › home › topics › get current year in javascript
Get the Current Year in JavaScript - Scaler Topics
May 4, 2023 - Then in the script tag, we have created the function example(). Under this function, we have created the object Date. We used the get current year in the javascript method to get the current year of the date.
freeCodeCamp
freecodecamp.org › news › javascript-get-current-date-todays-date-in-js
JavaScript Get Current Date – Today's Date in JS
November 7, 2024 - We'll make it more readable and understandable to users by using some JavaScript methods that operate on a date object. The date object supports numerous date methods, but for this article, we only need the current date and will only use three methods: getFullYear() – we will use this method to get the year as a four digit number (yyyy), for example 2022.