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()
メソッドは、協定世界時に基づき、指定された日時の「時」を返します。
試してみましょう
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()
返値
数値です。
Date
オブジェクトが有効な日時を表している場合、指定された日時の協定世界時での「時」を表す、0 から 23 までの整数を指定します。
それ以外の場合は、Date
オブジェクトが有効な日時を表していなければ NaN
が返されます。
例
getUTCHours() の使用
次の例は、現在時刻の「時」の部分を変数 hours
に代入します。
js
const today = new Date();
const hours = today.getUTCHours();
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-date.prototype.getutchours |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getUTCHours |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.