Ratgeber
Sekunden-vs-Millisekunden-Bug schnell erkennen
Kurze Checkliste, um Einheitenfehler bei Timestamps zügig zu finden.
Viele Timestamp-Bugs lassen sich in Minuten finden, wenn du zuerst die Einheit prüfst. So sparst du lange Debug-Schleifen.
Start with the visual digit test
Most seconds timestamps are 10 digits and milliseconds are 13 digits.
This quick check solves many issues before deeper debugging.
Use one expected real-world timestamp
Convert one value where you already know the event time.
If result year or hour is absurd, unit is likely wrong.
Check both conversion directions
Convert timestamp to date and date back to timestamp.
Round-trip checks expose hidden assumptions in parsing logic.
- Run test in UTC view.
- Run same value in local view.
- Compare with backend log output.
Inspect JavaScript and backend defaults
JavaScript Date constructors often expect milliseconds.
Many backend stores and APIs use seconds by default, so integration points need explicit conversion.
Add a guardrail for future payloads
Document expected unit in schema and enforce it with validation checks.
A small validator can stop repeated bugs across services.
Great for
- Dates unexpectedly near 1970.
- Future dates far beyond expected range.
- APIs and frontend showing different event times.
- Reviewing suspicious timestamps in incident logs.
Digit length check saves time
Start with digit length, then confirm one known value in UTC and local time.