JavaScript Tanggal setUTCHours()
Contoh
Atur jam ke 15, menurut waktu UTC:
const d = new Date();
d.setUTCHours(15);
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Metode setUTCHours() menyetel jam dari objek tanggal, menurut UTC.
Ini juga dapat digunakan untuk mengatur menit, detik, dan milidetik.
Catatan
UTC (Universal Time Coordinated) adalah waktu yang ditetapkan oleh Standar Waktu Dunia.
Waktu UTC sama dengan waktu GMT (Greenwich Mean Time).
Dukungan Peramban
setUTCHours()
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.setUTCHours(hour, min, sec, millisec)
Nilai Parameter
Parameter | Description |
---|---|
hour | Required. An integer representing the hour.
Expected values are 0-23, but other values are allowed:
|
min | Optional. An integer representing the minutes.
Expected values are 0-59, but other values are allowed:
|
sec | Optional. An integer representing the seconds
Expected values are 0-59, but other values are allowed:
|
millisec | Optional. An integer representing the milliseconds
Expected values are 0-999, but other values are allowed:
|
Detail Teknis
Nilai Kembali: | Angka, mewakili jumlah milidetik antara objek tanggal dan tengah malam 1 Januari 1970 |
---|---|
Versi JavaScript: | ECMAScript 1 |
Lebih Banyak Contoh
Contoh
Setel waktu ke 15:35:01 waktu UTC
const d = new Date();
d.setUTCHours(15, 35, 1);
Contoh
Setel waktu ke 48 jam yang lalu , menggunakan metode UTC:
const d = new Date();
d.setUTCHours(d.getUTCHours() - 48);