JavaScript Datum setUTCFullYear()
Příklad
Nastavte rok na 2015:
const d = new Date();
d.setUTCFullYear(2015);
Další příklady „Vyzkoušejte si to sami“ níže.
Definice a použití
Metoda setUTCFullYear() nastavuje rok objektu data podle UTC.
Poznámky
UTC (Universal Time Coordinated) je čas stanovený světovým časovým standardem.
Čas UTC je stejný jako čas GMT (Greenwichský střední čas).
Podpora prohlížeče
setUTCFullYear()
je funkce ECMAScript1 (ES1).
ES1 (JavaScript 1997) je plně podporován ve všech prohlížečích:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
Date.setUTCFullYear(year, month, day)
Hodnoty parametrů
Parameter | Description |
---|---|
year | Required. A value representing the year, negative values are allowed |
month | Optional. An integer representing the month
Expected values are 0-11, but other values are allowed:
|
day | Optional. An integer representing the day of month
Expected values are 1-31, but other values are allowed:
If the month has 31 days:
If the month has 30 days:
|
Návratová hodnota
Type | Description |
---|---|
Number | Milliseconds between the date object and midnight January 1 1970 |
Technické údaje
Verze JavaScriptu: | ECMAScript 1 |
---|
Další příklady
Příklad 2
Nastavte datum na 3. listopadu 2020, čas UTC:
const d = new Date();
d.setUTCFullYear(2020, 10, 3);
Příklad
Nastavte datum před šesti měsíci , čas UTC:
const d = new Date();
d.setUTCFullYear(d.getUTCFullYear, d.getUTCMonth() - 6);