Date.prototype.getHours()
getHours()
メソッドは、地方時に基づき、指定された日時の「時」を返します。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 https://github.com/mdn/interactive-examples をクローンしてプルリクエストを送信してください。
構文
dateObj.getHours()
返値
地方時に基づき、与えた日時の「時」を表す 0 から 23 の間の整数値。
例
getHours() の使用
以下の 2 行目の文は、 Date
オブジェクト Xmas95
の値に基づき、23 という値を変数 hours
に代入します。
let Xmas95 = new Date('December 25, 1995 23:15:30');
let hours = Xmas95.getHours();
console.log(hours); // 23
仕様書
ブラウザーの互換性
BCD tables only load in the browser