A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours below:

Date.prototype.getHours() - JavaScript | MDN

Date.prototype.getHours()

Baseline Widely available

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

試してみましょう
const birthday = new Date("March 13, 08 04:20");

console.log(birthday.getHours());
// 予想される結果: 4
構文 引数

なし。

返値

地方時に基づき、指定された日時の「時」を表す 0 から 23 の間の整数値です。日時が無効な場合は NaN を返します。

例 getHours() の使用

変数 hours には、 Date オブジェクト xmas95 に基づいて、 23 という値が入ります。

const xmas95 = new Date("1995-12-25T23:15:30");
const hours = xmas95.getHours();

console.log(hours); // 23
仕様書 ブラウザーの互換性 関連情報

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4