Set Date Methods
setDate() | Set the day as a number (1-31) |
setFullYear() | Set the year (optionally month and day) |
setHours() | Set the hour (0-23) |
setMilliseconds() | Set the milliseconds (0-999) |
setMinutes() | Set the minutes (0-59) |
setMonth() | Set the month (0-11) |
setSeconds() | Set the seconds (0-59) |
setTime() | Set the time (milliseconds since January 1, 1970) |
setFullYear() Method
sets the year of a date object.
<p id="demo"></p>
<script>
const d = new Date();
d.setFullYear(2020);
document.getElementById("demo").innerHTML = d;
</script>
Tue Nov 17 2020 08:51:07 GMT+0900 (대한민국 표준시)
can optionally set month and day.
<p id="demo"></p>
<script>
const d = new Date();
d.setFullYear(2020, 11, 3);
document.getElementById("demo").innerHTML = d;
</script>
Thu Dec 03 2020 08:51:49 GMT+0900 (대한민국 표준시)
'JavaScript' 카테고리의 다른 글
JavaScript - Booleans (0) | 2022.11.17 |
---|---|
JavaScript - Math Object (0) | 2022.11.17 |
JavaScript - Date Formats (0) | 2022.11.16 |
JavaScript - Array Iteration (0) | 2022.11.15 |
JavaScript - Sorting Arrays (0) | 2022.11.15 |