グローバルツールハブ
現在の言語: Japanese
ガイド一覧へ戻る

ガイド

JavaScriptでタイムスタンプ表示がずれる理由

秒・ミリ秒の混同やタイムゾーン設定による日付ずれを解消します。

Dateオブジェクト自体より、入力単位や表示方法の違いが原因になるケースが多いです。

JavaScript Date expects milliseconds

new Date(value) expects milliseconds in most timestamp workflows.

Passing seconds directly creates incorrect output.

Local time vs UTC confusion

Some methods show local timezone by default.

Use UTC-aware formatting when you need environment-independent results.

Debug checklist

Follow this order to isolate the issue quickly.

  • Confirm unit length.
  • Convert to UTC and local for comparison.
  • Check source API timezone assumptions.

Avoid hidden string parsing issues

Different date string formats can parse inconsistently.

Prefer numeric timestamps or ISO-8601 strings for predictable behavior.

Typical problems

  • Date near 1970 appears unexpectedly.
  • Correct day but wrong hour.
  • Different time in frontend vs backend.
  • Broken date formatting in UI.

Debug unit first, timezone second

Most JavaScript timestamp bugs are solved by checking units and then checking timezone conversion.

関連ツール

タイムスタンプ変換

Unix秒、Unixミリ秒、日時テキストをブラウザ内で双方向に変換できます。

Open Timestamp Converter

あわせて読みたいガイド

近い作業フローを扱う別の短い記事も確認できます。