Tanggal JavaScript.UTC()
Contoh
Dapatkan jumlah milidetik antara tanggal dan 1 Januari 1970:
let ms = Date.UTC(2020, 02, 30);
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Metode Date.UTC() mengembalikan jumlah milidetik antara tanggal yang ditentukan dan tengah malam 1 Januari 1970, 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
Date.UTC()
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.UTC(year, month, day, hours, minutes, seconds, millisec)
Date.UTC() adalah metode statis dari objek Date.
Anda tidak dapat menggunakannya pada tanggal seperti d.UTC()
Sintaksnya selalu Date.UTC().
Nilai Parameter
Parameter | Description |
---|---|
year | Required. A four-digit value representing the year, negative values are allowed |
month | Required. 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:
|
hour | Optional. Default 0. An integer representing the hour.
Expected values are 0-23, but other values are allowed:
|
min | Optional. Default 0. An integer representing the minutes.
Expected values are 0-59, but other values are allowed:
|
sec | Optional. Default 0. An integer representing the seconds
Expected values are 0-59, but other values are allowed:
|
millisec | Optional. Default 0. An integer representing the milliseconds
Expected values are 0-999, but other values are allowed:
|
Detail Teknis
Nilai Kembali: | Angka, mewakili jumlah milidetik antara tanggal-waktu yang ditentukan dan tengah malam 1 Januari 1970 |
---|---|
Versi JavaScript: | ECMAScript 1 |
Lebih Banyak Contoh
Contoh
Buat objek tanggal menggunakan waktu UTC alih-alih waktu lokal:
let d = new Date(Date.UTC(2020, 02, 30));