このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。
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 2015年7月.
getUTCHours() はDate インスタンスのメソッドで、協定世界時に基づき、指定された日時の「時」を返します。
In this article
試してみましょう
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());// 予想される結果: 12console.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> |