JavaScript Date.UTC()
例
日付から1970年1月1日までのミリ秒数を取得します。
let ms = Date.UTC(2020, 02, 30);
以下の「自分で試してみてください」の例をもっと見てください。
定義と使用法
Date.UTC()メソッドは、UTCに従って、指定された日付から1970年1月1日の午前0時までのミリ秒数を返します。
ノート
UTC(協定世界時)は、世界時間標準によって設定された時間です。
UTC時間はGMT時間(グリニッジ標準時)と同じです。
ブラウザのサポート
Date.UTC()
ECMAScript1(ES1)機能です。
ES1(JavaScript 1997)は、すべてのブラウザーで完全にサポートされています。
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
構文
Date.UTC(year, month, day, hours, minutes, seconds, millisec)
Date.UTC()は、Dateオブジェクトの静的メソッドです。
d.UTC()のような日付では使用できません
構文は常にDate.UTC()です。
パラメータ値
Parameter | Description |
---|---|
year | Required. A four-digit value representing the year, negative values are allowed |
month | Required. An integer representing the month
Expected values are 0-11, but other values are allowed:
|
day | Optional. An integer representing the day of month
Expected values are 1-31, but other values are allowed:
If the month has 31 days:
If the month has 30 days:
|
hour | Optional. Default 0. An integer representing the hour.
Expected values are 0-23, but other values are allowed:
|
min | Optional. Default 0. An integer representing the minutes.
Expected values are 0-59, but other values are allowed:
|
sec | Optional. Default 0. An integer representing the seconds
Expected values are 0-59, but other values are allowed:
|
millisec | Optional. Default 0. An integer representing the milliseconds
Expected values are 0-999, but other values are allowed:
|
技術的な詳細
戻り値: | 指定された日時から1970年1月1日午前0時までのミリ秒数を表す数値 |
---|---|
JavaScriptバージョン: | ECMAScript 1 |
その他の例
例
現地時間の代わりにUTC時間を使用して日付オブジェクトを作成します。
let d = new Date(Date.UTC(2020, 02, 30));