JavaScript Date setFullYear ()
Beispiel 1
const d = neues Datum ();
d.setFullYear(2020);
Definition und Verwendung
setFullYear()
setzt das Jahr eines Datums.
setFullYear()
kann auch Monat und Tag einstellen.
Beispiel 2
const d = new Date();
d.setFullYear(2020, 10, 3);
Beispiel 3
Stellen Sie das Datum auf vor sechs Monaten ein :
const d = new Date();
d.setFullYear(d.getFullYear(), d.getMonth() - 6);
Browser-Unterstützung
setFullYear()
ist eine ECMAScript1 (ES1)-Funktion.
ES1 (JavaScript 1997) wird in allen Browsern vollständig unterstützt:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
Date.setFullYear(year, month, day)
Parameter
year | Required. The year. Negative values are allowed. |
month | Optional. The month (0 to 11). Higher and lower values are handeled with date maths:
|
day | Optional. The day (0 to 31). Higher and lower values are handeled with date maths:
|
Rückgabewert
Eine Zahl. Anzahl der Millisekunden zwischen dem Datum und dem 1. Januar 1970 00:00:00 UTC. |