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
Bitwise AND Bitwise OR Bitwise NOT Bitwise XOR Bitwise Left Bitwise Right Bitwise Signed JS Misc Operators · : ?. ... () ? x : y => delete in instanceof typeof void JS Precedence JS Promises · all() allSettled() any() catch() finally() race() reject() resolve() then() try() withResolvers() JS Proxy · apply() construct() defineProperty() deleteProperty() get() getOwnPropertyDescriptor() getPrototypeOf() has() isExtensible() ownKeys() preventExtentions() set() setPrototypeOf() JS Reflect
jquery - how to display current month, year in javascript using div - Stack Overflow
I'm trying to get a jquery or java-script code for displaying the current month and year in a div, but unable so far. I mean I want to display the current month and year in this format:October 2012... More on stackoverflow.com
How to get year/month/day from a date object?
alert(dateObj) gives Wed Dec 30 2009 00:00:00 GMT+0800 How to get date in format 2009/12/30? More on stackoverflow.com
Check if it is the first day of the month or first day of the year
from datetime import datetime today = datetime.now() if today.day == 1: print("It's the first of the month!") if today.month == 1: print("It's the first of the year!") More on reddit.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
Videos
01:40
How to easily Get the Current Date and Year using JavaScript - YouTube
05:02
How to Get Current Date & Time in JavaScript | Date Object Tutorial ...
Get the current year in JavaScript - Stack Overflow - YouTube
Get the Day of the Year of a Date in JavaScript - YouTube
00:47
The Proper way to get Date in JS #programming #javascript #tip ...
09:14
Javascript Date | getDate() | getMonth() | getFullYear() | Javascript ...
W3Schools
w3schools.com › js › js_date_methods.asp
JavaScript Get Date Methods
JS Examples JS HTML DOM JS HTML ... ... In JavaScript, date objects are created with new Date(). new Date() returns a date object with the current date and time. ... The get methods above return Local time....
Top answer 1 of 7
23
JavaScript doesn't natively implement strftime, so you'll have to do something a bit less elegant:
window.onload = function() {
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];;
var date = new Date();
document.getElementById('date').innerHTML = months[date.getMonth()] + ' ' + date.getFullYear();
};
I'm assuming that you have an element with an id of date somewhere in your HTML.
2 of 7
12
there's no inbuild function in javascript to get full name of month. You can create an array of month names and use it to get full month name for e.g
var m_names = ['January', 'February', 'March',
'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December'];
d = new Date();
var n = m_names[d.getMonth()];
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getFullYear
Date.prototype.getFullYear() - JavaScript - MDN - Mozilla
July 10, 2025 - This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015. ... The getFullYear() method of Date instances returns the year for this date according to local time.
IncludeHelp
includehelp.com › code-snippets › get-current-date-month-and-year-in-javascript.aspx
Get current date, month and year in JavaScript - IncludeHelp
October 28, 2017 - Note that, it returns value ranging from 0 to 11 for 12 months. This means January is 0 and December is 11. Here is an example, var today = new Date(); var month = today.getMonth(); // Returns 9 console.log(month); // Output: 9 · To get the current year, use the getFullYear() method.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getMonth
Date.prototype.getMonth() - JavaScript - MDN - Mozilla
July 10, 2025 - const xmas95 = new Date("1995-12-25T23:15:30"); const month = xmas95.getMonth(); console.log(month); // 11
Scaler
scaler.com › home › topics › get current year in javascript
Get the Current Year in JavaScript - Scaler Topics
May 4, 2023 - The example is described below with output and explanation. In this example, we have used the get the getFullYear() method to get the current year that corresponds to the current local time.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getYear
Date.prototype.getYear() - JavaScript - MDN - Mozilla
July 10, 2025 - This method essentially returns the value of getFullYear() minus 1900. You should use getFullYear() instead, so that the year is specified in full. The second statement assigns the value 95 to the variable year. ... The second statement assigns the value 100 to the variable year.
W3Schools
w3schools.com › jsref › jsref_getmonth.asp
JavaScript Date getMonth() Method
cssText getPropertyPriority() ... ... const month = ["January","February","March","April","May","June","July","August","September","October","November","December"]; const d = new Date(); let name = month[d.getMonth()]; Try it Yourself ...
Top answer 1 of 16
615
const dateObj = new Date();
const month = dateObj.getUTCMonth() + 1; // months from 1-12
const day = dateObj.getUTCDate();
const year = dateObj.getUTCFullYear();
const newDate = year + "/" + month + "/" + day;
// Using template literals:
const newDate = `${year}/${month}/${day}`;
// Using padded values, so that 2023/1/7 becomes 2023/01/07
const pMonth = month.toString().padStart(2,"0");
const pDay = day.toString().padStart(2,"0");
const newPaddedDate = `${year}/${pMonth}/${pDay}`;
or you can set new date and give the above values
2 of 16
208
new Date().toISOString()
"2016-02-18T23:59:48.039Z"
new Date().toISOString().split('T')[0];
"2016-02-18"
new Date().toISOString().replace('-', '/').split('T')[0].replace('-', '/');
"2016/02/18"
new Date().toLocaleString().split(',')[0]
"2/18/2016"