JavaScriptの日付setUTCHours()
例
UTC時間に従って、時間を15に設定します。
const d = new Date();
d.setUTCHours(15);
以下の「自分で試してみてください」の例をもっと見てください。
定義と使用法
setUTCHours()メソッドは、UTCに従って日付オブジェクトの時間を設定します。
また、分、秒、ミリ秒を設定するために使用することもできます。
ノート
UTC(協定世界時)は、世界時間標準によって設定された時間です。
UTC時間はGMT時間(グリニッジ標準時)と同じです。
ブラウザのサポート
setUTCHours()
ECMAScript1(ES1)機能です。
ES1(JavaScript 1997)は、すべてのブラウザーで完全にサポートされています。
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
構文
Date.setUTCHours(hour, min, sec, millisec)
パラメータ値
Parameter | Description |
---|---|
hour | Required. An integer representing the hour.
Expected values are 0-23, but other values are allowed:
|
min | Optional. An integer representing the minutes.
Expected values are 0-59, but other values are allowed:
|
sec | Optional. An integer representing the seconds
Expected values are 0-59, but other values are allowed:
|
millisec | Optional. An integer representing the milliseconds
Expected values are 0-999, but other values are allowed:
|
技術的な詳細
戻り値: | 日付オブジェクトから1970年1月1日午前0時までのミリ秒数を表す数値 |
---|---|
JavaScriptバージョン: | ECMAScript 1 |
その他の例
例
時刻を15:35:01UTC時刻に設定します
const d = new Date();
d.setUTCHours(15, 35, 1);
例
UTCメソッドを使用して、時刻を48時間前に設定します。
const d = new Date();
d.setUTCHours(d.getUTCHours() - 48);