Ustawienie daty JavaScriptUTCFullYear()
Przykład
Ustaw rok na 2015:
const d = new Date();
d.setUTCFullYear(2015);
Więcej przykładów „Wypróbuj sam” poniżej.
Definicja i użycie
Metoda setUTCFullYear() ustawia rok obiektu daty zgodnie z UTC.
Uwagi
UTC (Universal Time Coordinated) to czas ustawiony przez Światowy Standard Czasu.
Czas UTC jest taki sam jak czas GMT (Greenwich Mean Time).
Obsługa przeglądarki
setUTCFullYear()
to funkcja ECMAScript1 (ES1).
ES1 (JavaScript 1997) jest w pełni obsługiwany we wszystkich przeglądarkach:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Składnia
Date.setUTCFullYear(year, month, day)
Wartości parametrów
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:
|
Wartość zwrotu
Type | Description |
---|---|
Number | Milliseconds between the date object and midnight January 1 1970 |
Szczegóły techniczne
Wersja JavaScript: | ECMAScript 1 |
---|
Więcej przykładów
Przykład 2
Ustaw datę na 3 listopada 2020 r., czas UTC:
const d = new Date();
d.setUTCFullYear(2020, 10, 3);
Przykład
Ustaw datę na sześć miesięcy temu , czas UTC:
const d = new Date();
d.setUTCFullYear(d.getUTCFullYear, d.getUTCMonth() - 6);