レッスン 2

Seconds vs Milliseconds 日本語ガイド

日本語の timestamp seconds vs milliseconds ガイド: Ten-digit vs thirteen-digit values and how to avoid off-by-1000 bugs.

このコンテンツはまだ日本語で用意されていません。ローカライズが完了するまで English 版を表示しています。

Unix time is defined in seconds, but many runtimes expose milliseconds for finer precision. Mixing the two is one of the most common timestamp bugs.

The digit-count heuristic

Rough rule of thumb in decimal form:

DigitsUsually meansExample
10Seconds1700000000
13Milliseconds1700000000000

Values with other lengths need context—always confirm against API documentation.

Why both exist

  • Seconds — compact, enough for many logs and JWT expiry; used by time.time() in Python, many C APIs, and Linux date +%s
  • Milliseconds — JavaScript Date.now(), Java System.currentTimeMillis(), some JSON APIs for sub-second ordering

Converting between them is multiplication or division by 1000—when you pick the wrong direction, dates jump to 1970 or the far future.

Fractional seconds

Some systems return floating-point seconds (1700000000.123). That is still “seconds + fraction,” not milliseconds. Parsing it as an integer millisecond field loses precision or fails validation.

Defensive habits

  1. Read the API schema or sample payload first
  2. If a date looks wrong by ~1000×, swap units mentally
  3. Store internally in one convention (often ms or µs in app code) and convert at boundaries
  4. In databases, prefer TIMESTAMPTZ types when available instead of naked integers

Key takeaway

Seconds and milliseconds name the same timeline with different scales. Know which scale your source uses before you convert or compare.

実践したいときは関連する DevCove ツールを使えます。任意であり、このレッスンの必須部分ではありません。

関連ツールを開く

コース概要へ戻る