Date.prototype.getHours()

getHours() メソッドは、地方時に基づき、指定された日時の「時」を返します。

試してみましょう

構文

js
getHours()

返値

地方時に基づき、与えた日時の「時」を表す 0 から 23 の間の整数値。

getHours() の使用

以下の 2 行目の文は、 Date オブジェクトである xmas95 の値に基づき、23 という値を変数 hours に代入します。

js
const xmas95 = new Date("December 25, 1995 23:15:30");
const hours = xmas95.getHours();

console.log(hours); // 23

仕様書

Specification
ECMAScript Language Specification
# sec-date.prototype.gethours

ブラウザーの互換性

BCD tables only load in the browser

関連情報