クイックリファレンス

JavaScript Date オブジェクト チートシート

JavaScript 組み込み Date オブジェクトのリファレンス:インスタンス生成、タイムスタンプ取得、各種ゲッター/セッター、日時演算とフォーマット。

· 公開日

JavaScript の組み込み Date オブジェクトは、Unix エポック (1970年1月1日 00:00:00 UTC) からの経過時間をミリ秒単位で表します。

Date インスタンスの生成

const now = new Date();                        // 現在の日時
const epoch = new Date(1730000000000);         // エポックミリ秒から生成
const iso = new Date('2026-10-25T14:30:00Z');  // ISO 8601 形式の文字列から生成
const custom = new Date(2026, 9, 25, 14, 30);  // 年、月 (0が1月)、日、時、分

日時取得メソッド (Getters)

メソッド ローカル時刻 対応する UTC メソッド
getFullYear() 4桁の西暦年 getUTCFullYear()
getMonth() 月インデックス (0〜11) getUTCMonth()
getDate() 日 (1〜31) getUTCDate()
getDay() 曜日 (0が日曜日) getUTCDay()
getHours() 時 (0〜23) getUTCHours()
getMinutes() 分 (0〜59) getUTCMinutes()
getSeconds() 秒 (0〜59) getUTCSeconds()
getMilliseconds() ミリ秒 (0〜999) getUTCMilliseconds()
getTime() Unix エポックからの経過ミリ秒 (same timestamp)

日時の計算と差分の算出

// 日付に7日を加算
const target = new Date();
target.setDate(target.getDate() + 7);

// 2つの日付間の差 (日数単位)
const d1 = new Date('2026-10-01');
const d2 = new Date('2026-10-25');
const diffMs = d2 - d1;
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24)); // => 24

日時のフォーマットと表示

const date = new Date('2026-10-25T14:30:00Z');

date.toISOString();        // "2026-10-25T14:30:00.000Z"
date.toDateString();       // "Sun Oct 25 2026"
date.toTimeString();       // "14:30:00 GMT+0000"
date.toLocaleDateString(); // e.g. "10/25/2026"

関連リファレンス

関連テーマ