Date【日時】オブジェクト

メモ ( メソッド分類 ) 日時文字列フォーマット コンストラクタ・型変換 プロパティ一覧 メソッド一覧

メモ

概要

  • 1970/01/01 00:00:00 UTC からのミリ秒数
    • 有効範囲:±100,000,000 日 (±約273,790年:-271821/04/20 ~ 275760/07/13)
      約285,616年 (Number【数値型】の有効範囲) は記述ミス ( 修正 )
    • うるう秒の考慮なし (関連のECMAScript 'Time Values and Time Range' (英語) 参照)
    • -0 は存在しない (+0 は存在)
    • クラス定義による継承可能
  • 簡易的な処理時間の計測 (精度を求めない重い処理の特定等)
    • 処理の前後で経過時間を取得し、差を計算  (now【現在の経過ミリ秒取得 (UTC)】 )
    • コンソールに表示を限定する場合、consoleのtime【タイマー スタート】・timeEnd【タイマー ストップ】を使用

用語

  • UTC:協定世界時 (Coordinated Universal Time) セシウム原子の振動数を基にした時刻
  • GMT:グリニッジ標準時 (Greenwich Mean Time) 地球の自転を基にした時刻

メソッド分類

文字列 (日時文字列フォーマット) ⇔ 日時 (その他変換)
文字列 経過ミリ秒
日時文字列 解析 parse
文字列・経過ミリ秒・個別指定・現在日時 日時
コンストラクタ new Date 【日時文字列 指定】
new Date 【経過ミリ秒 指定】
new Date 【年・月 等 個別指定】
new Date 【未指定:現在日時】
日時 文字列
UTCローカル時刻 (上段)
ロケール (下段)
ISOJSONGMT
日時文字列 変換 toUTCString toString (実装依存)
ユーザ作成フォーマット関数
toISOString toJSON toGMTString
toLocaleString
(参考)
Intl.DateTimeFormat
日付文字列 変換toDateString (実装依存)
toLocaleDateString
時刻文字列 変換toTimeString (実装依存)
toLocaleTimeString
現在日時文字列 変換Date【型変換】

日時文字列フォーマット

  • ISO 8601 拡張形式 (- と : で区切り) の簡易版 (その他の形式については、実装依存)
    • 日付形式のみ (例:2001-02-03)
    • 日付形式+時間形式 (例:2001-02-03T04:05:06.007)
    • 日付形式+時間形式+タイムゾーンオフセット (例:2001-02-03T04:05:06.078+09:00)
日付形式
形式備考
YYYY月日省略 (1月1日)
±YYYYYY
YYYY-MM日省略 (1日)
±YYYYYY-MM
YYYY-MM-DD省略なし
±YYYYYY-MM-DD
時間形式
形式備考
THH:mm秒・ミリ秒省略 (00.000 秒)
THH:mm:ssミリ秒省略 (000 ミリ秒)
THH:mm:ss.sss省略なし
フィールド
フィールド範囲備考
YYYY0000 ~ 9999グレゴリオ暦 0000~9999年
+YYYYYY+000000 ~ 275760紀元前 1年~275,760年 (拡大表記)
-YYYYYY-271821 ~ -000001紀元前 271,822年 ~ 紀元前 2年 (拡大表記)
MM01~12
DD01~31
HH00~24時 (24:翌日の0時)
mm00~59
ss00~59
ミリ秒sss000~999ミリ秒
タイムゾーン
オフセット
省略UTC時刻
ローカル時刻
日付のみはUTC時刻、日付+時刻はローカル時刻
参照:new Date【コンストラクタ】parse【日時文字列解析】
ZUTC からのオフセット 0
+HH:mm+00:00 ~ +23:59UTC からのオフセット時間
(+09:00:日本標準時)
-HH:mm-00:00 ~ -23:59
セパレータ -年・月・日の間の区切り
T日付・時間の間の区切り
:時・分・秒の間の区切り
.秒・ミリ秒の間の区切り

コンストラクタ・型変換

構文説明

(1) new Date ( year, month [, date [, hours [, minutes [, seconds [, ms ] ] ] ] ] )
(2) new Date ( value )
(3) new Date ()
コンストラクタ
(1) 指定日時 (ローカル時刻)
(2) 日時文字列 または 指定ミリ秒 (UTC)
(3) 現在日時
Date ( [ year [, month [, date [, hours [, minutes [, seconds [, ms ] ] ] ] ] ] ] ) 型変換 (現在日時文字列)

プロパティ一覧

プロパティ説明
Date.prototype.constructorコンストラクタ定義
Date.prototypeプロトタイプ

メソッド一覧

分類した一覧は メソッド分類 参照

メソッド説明
Date.prototype [@@toPrimitive] ( hint ) プリミティブ値取得 ([Symbol.toPrimitive])
Date.prototype.getDate () 日取得 (ローカル時刻)
Date.prototype.getDay () 曜日取得 (ローカル時刻)
Date.prototype.getFullYear () 年取得 (ローカル時刻)
Date.prototype.getHours () 時取得 (ローカル時刻)
Date.prototype.getMilliseconds () ミリ秒取得 (ローカル時刻)
Date.prototype.getMinutes () 分取得 (ローカル時刻)
Date.prototype.getMonth () 月取得 (ローカル時刻)
Date.prototype.getSeconds () 秒取得 (ローカル時刻)
Date.prototype.getTime () 経過ミリ秒取得 (UTC)
Date.prototype.getTimezoneOffset () UTCとの時差取得 (分単位)
Date.prototype.getUTCDate () 日取得 (UTC)
Date.prototype.getUTCDay () 曜日取得 (UTC)
Date.prototype.getUTCFullYear () 年取得 (UTC)
Date.prototype.getUTCHours () 時取得 (UTC)
Date.prototype. getUTCMilliseconds () ミリ秒取得 (UTC)
Date.prototype.getUTCMinutes () 分取得 (UTC)
Date.prototype.getUTCMonth () 月取得 (UTC)
Date.prototype.getUTCSeconds () 秒取得 (UTC)
Date.prototype. getYear ()   相対年取得 (ローカル時刻)
Date. now () 現在の経過ミリ秒取得 (UTC)
Date. parse ( string ) 日時文字列解析
Date.prototype. setDate ( date ) 日設定 (ローカル時刻)
Date.prototype.setFullYear ( year [, month [, date ] ] ) 年月日設定 (ローカル時刻)
Date.prototype.setHours ( hour [, min [, sec [, ms ] ] ] ) 時分秒設定 (ローカル時刻)
Date.prototype. setMilliseconds ( ms ) ミリ秒設定 (ローカル時刻)
Date.prototype.setMinutes ( min [, sec [, ms ] ] ) 分秒設定 (ローカル時刻)
Date.prototype. setMonth ( month [, date ] ) 月日設定 (ローカル時刻)
Date.prototype. setSeconds ( sec [, ms ] ) 秒設定 (ローカル時刻)
Date.prototype. setTime ( time ) 経過ミリ秒設定 (UTC)
Date.prototype. setUTCDate ( date ) 日設定 (UTC)
Date.prototype.setUTCFullYear ( year [, month [, date ] ] ) 年月日設定 (UTC)
Date.prototype.setUTCHours ( hour [, min [, sec [, ms ] ] ] ) 時分秒設定 (UTC)
Date.prototype. setUTCMilliseconds ( ms ) ミリ秒設定 (UTC)
Date.prototype.setUTCMinutes ( min [, sec [, ms ] ] ) 分秒設定 (UTC)
Date.prototype.setUTCMonth ( month [, date ] ) 月日設定 (UTC)
Date.prototype.setUTCSeconds ( sec [, ms ] ) 秒設定 (UTC)
Date.prototype.setYear ( year ) 年設定 (ローカル時刻)
Date.prototype.toDateString () 日付文字列変換 (ローカル時刻)
Date.prototype. toGMTString () 日時文字列変換 (GMT)
Date.prototype.toISOString () 日時文字列変換 (ISO)
Date.prototype.toJSON ( key ) JSON テキスト変換
Date.prototype. toLocaleDateString ()
toLocaleDateString ( [ reserved1 [ , reserved2 ] ] )
toLocaleDateString ( [locales [, options]])
ロケール日付文字列変換 (ローカル時刻)
Date.prototype. toLocaleString ()
toLocaleString ( [ reserved1 [ , reserved2 ] ] )
toLocaleString ( [locales [, options ] ] )
ロケール日時文字列変換 (ローカル時刻)
Date.prototype. toLocaleTimeString ()
toLocaleTimeString ( [ reserved1 [ , reserved2 ] ] )
toLocaleTimeString ( [ locales [, options]] )
ロケール時刻文字列変換 (ローカル時刻)
Date.prototype. toString () 文字列変換
Date.prototype.toTimeString () 時刻文字列変換 (ローカル時刻)
Date.prototype.toUTCString () 日時文字列変換 (UTC)
Date.UTC (year, month [, date [, hours [, minutes [, seconds [, ms ] ] ] ] ] ) UTC日時のミリ秒数取得
Date.prototype. valueOf ()ミリ秒数取得