JavaScript Tanggal setUTCFullYear()
Contoh
Atur tahun ke 2015:
const d = new Date();
d.setUTCFullYear(2015);
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Metode setUTCFullYear() menetapkan tahun objek tanggal, menurut UTC.
Catatan
UTC (Universal Time Coordinated) adalah waktu yang ditetapkan oleh Standar Waktu Dunia.
Waktu UTC sama dengan waktu GMT (Greenwich Mean Time).
Dukungan Peramban
setUTCFullYear()
adalah fitur ECMAScript1 (ES1).
ES1 (JavaScript 1997) didukung penuh di semua browser:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Sintaksis
Date.setUTCFullYear(year, month, day)
Nilai Parameter
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:
|
Nilai Kembali
Type | Description |
---|---|
Number | Milliseconds between the date object and midnight January 1 1970 |
Detail Teknis
Versi JavaScript: | ECMAScript 1 |
---|
Lebih Banyak Contoh
Contoh 2
Atur tanggal menjadi 3 November 2020, waktu UTC:
const d = new Date();
d.setUTCFullYear(2020, 10, 3);
Contoh
Setel tanggal menjadi enam bulan yang lalu , waktu UTC:
const d = new Date();
d.setUTCFullYear(d.getUTCFullYear, d.getUTCMonth() - 6);