January is month 0. December is month 11.
So this should work:
var d = new Date(2016, 11, 17, 0, 0, 0, 0);
Also, you can just simply do:
var d = new Date(2016, 11, 17);
Answer from Dean Coakley on Stack OverflowW3Schools
w3schools.com › js › js_dates.asp
W3Schools.com
JS Examples JS HTML DOM JS HTML ... Date Objects let us work with dates: Year: Month: Day: Hours: Minutes: Seconds: const d = new Date(); Try it Yourself » ·...
Top answer 1 of 2
121
January is month 0. December is month 11.
So this should work:
var d = new Date(2016, 11, 17, 0, 0, 0, 0);
Also, you can just simply do:
var d = new Date(2016, 11, 17);
2 of 2
67
According to MDN - Date:
month
Integer value representing the month, beginning with 0 for January to 11 for December.
You should subtract 1 from your month:
const d = new Date(2016, 11, 17, 0, 0, 0, 0);
Videos
Get the Day of the Year of a Date in JavaScript - YouTube
Create a Year Day prototype for Date in JavaScript - YouTube
08:02
Learn JavaScript DATE objects in 8 minutes! 📅 - YouTube
07:37
JavaScript Date Object Tutorial (2025): Format, Parse & Fix Timezones ...
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
Returns the day of the month (1 – 31) for the specified date according to local time. ... Returns the day of the week (0 – 6) for the specified date according to local time. ... Returns the year (4 digits for 4-digit years) of the specified date according to local time.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › Date
Date() constructor - JavaScript | MDN
For example, new Date(2020, 5, 0) will return May 31st, 2020. ... Integer value representing the year. Values from 0 to 99 map to the years 1900 to 1999. All other values are the actual year. See the example. ... Integer value representing the month, beginning with 0 for January to 11 for December.
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"
W3Schools
w3schools.com › js › js_date_methods.asp
JavaScript Get Date Methods
The getFullYear() method returns ... code might use the non-standard method getYear(). ... The getMonth() method returns the month of a date as a number (0-11)....
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Representing_dates_times
Representing dates & times - JavaScript | MDN
The exact forms supported differ among engines, but the following form is always supported: YYYY-MM-DDTHH:mm:ss.sssZ. For example, xmas95 = new Date("1995-12-25"). If you omit hours, minutes, or seconds, the value will be set to zero. A set of integer values for year, month, and day.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getMonth
Date.prototype.getMonth() - JavaScript | MDN
The getMonth() method of Date instances returns the month for this date according to local time, as a zero-based value (where zero indicates the first month of the year). const moonLanding = new Date("July 20, 69 00:20:18"); console.log(moonLanding.getMonth()); // (January gives 0) // Expected ...
Top answer 1 of 2
3
According to the documentation, you can use date.getFullYear() to get the year in YYYY format and date.getMonth() to get the month.
An example:
let list = document.getElementById('test');
let date = new Date(2008, 4, 15);
// year
let yearNode = document.createElement("li");
yearNode.appendChild(document.createTextNode(date.getFullYear()));
list.appendChild(yearNode)
// year + month
let yearMonthNode = document.createElement("li");
yearMonthNode.appendChild(document.createTextNode(date.getFullYear() + " " + date.getMonth()))
list.appendChild(yearMonthNode)
<ul id="test">
</ul>
2 of 2
0
with date.getMonth() you need +1 to this
var month = date.getMonth() + 1
Moment.js
momentjs.com › docs
Moment.js | Docs
Day of Month (1 or 2 digit), followed by a three-letter month and 2 or 4 digit year · Two-digit hours and minutes separated by a colon (:), followed optionally by another colon and seconds in 2-digits · Timezone or offset in one of the following formats: ... The parser also confirms that ...
freeCodeCamp
freecodecamp.org › news › javascript-date-format-how-to-format-a-date-in-js
JavaScript Date Format – How to Format a Date in JS
November 7, 2024 - let stringDate = Date(); console.log(stringDate); // "Tue Aug 23 2022 14:47:12 GMT-0700 (Pacific Daylight Time)" let objectDate = new Date(); console.log(objectDate); // Tue Aug 23 2022 14:47:12 GMT-0700 (Pacific Daylight Time) These full format dates comprise the day, month, year, minute, hour, and other information you don't need all the time.
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-the-first-day-of-the-year-in-javascript
How to get the first day of the year in JavaScript ? - GeeksforGeeks
July 12, 2025 - Example: This example uses the ... = new Date(); console.log("Today = " + date); // Use Date(year, month, day) function console.log(new Date(date.getFullYear(), 0, 1));...
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-date-objects
JavaScript Date Objects - GeeksforGeeks
July 11, 2025 - You can perform various date manipulations such as adding or subtracting days, months, or years to/from a specific date. ... let cDate = new Date(); cDate.setDate(cDate.getDate() + 5); // Adds 5 days to the current date console.log(cDate);