Date.prototype.getUTCHours()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
getUTCHours()
は Date
インスタンスのメソッドで、協定世界時に基づき、指定された日時の「時」を返します。
試してみましょう
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());
// 予想される結果: 12
console.log(date2.getUTCHours());
// 予想される結果: 10
構文
js
getUTCHours()
引数
なし。
返値
指定された日時の、協定世界時に基づく「時」を表す 0 から 23 までの整数です。日時が無効な場合は NaN
を返します。
例
getUTCHours() の使用
次の例は、現在時刻の「時」の部分を変数 hours
に代入します。
js
const today = new Date();
const hours = today.getUTCHours();
仕様書
Specification |
---|
ECMAScript® 2026 Language Specification # sec-date.prototype.getutchours |