試一試
const date1 = new Date("December 31, 1975, 23:15:30 GMT+11:00");
const date2 = new Date("December 31, 1975, 23:15:30 GMT-11:00");
console.log(date1.getUTCHours());
// Expected output: 12
console.log(date2.getUTCHours());
// Expected output: 10
語法
js
getUTCHours()
引數
無。
返回值
返回一個介於 0 和 23 之間的整數,表示給定日期根據通用時間(UTC)的小時。如果日期 無效,則返回 NaN。
示例
使用 getUTCHours()
以下示例將當前時間的時部分賦值給變數 hours。
js
const today = new Date();
const hours = today.getUTCHours();
規範
| 規範 |
|---|
| ECMAScript® 2026 語言規範 # sec-date.prototype.getutchours |
瀏覽器相容性
載入中…