--- title: Date.prototype.getHours() slug: Web/JavaScript/Reference/Global_Objects/Date/getHours tags: - Date - JavaScript - Method - Prototype - Reference - メソッド translation_of: Web/JavaScript/Reference/Global_Objects/Date/getHours ---
getHours()
メソッドは、地方時に基づき、指定された日時の「時」を返します。
このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 https://github.com/mdn/interactive-examples をクローンしてプルリクエストを送信してください。
dateObj.getHours()
地方時に基づき、与えた日時の「時」を表す 0 から 23 の間の整数値。
以下の 2 行目の文は、 {{jsxref("Global_Objects/Date", "Date")}} オブジェクト Xmas95
の値に基づき、23 という値を変数 hours
に代入します。
let Xmas95 = new Date('December 25, 1995 23:15:30'); let hours = Xmas95.getHours(); console.log(hours); // 23
仕様書 |
---|
{{SpecName('ESDraft', '#sec-date.prototype.gethours', 'Date.prototype.getHours')}} |
{{Compat("javascript.builtins.Date.getHours")}}