
Unix timestamps, UTC, and local time: how to avoid log confusion
A timestamp identifies an instant, while a displayed date includes a time-zone interpretation. Confusing the two can make correct logs appear inconsistent.
What a Unix timestamp is
A Unix timestamp is a count of seconds since the Unix epoch, which is 1 January 1970 at 00:00:00 UTC, not counting leap seconds. The value 0 means that exact instant, and every second after it adds one. Because the count is defined against UTC, the timestamp itself has no time zone. Two systems in different parts of the world that agree on the timestamp agree on the instant, even if their clocks display different wall-clock times. That is the main reason timestamps are so useful for logs, APIs, and databases: they give every system a single, unambiguous way to name a moment.
A displayed date, by contrast, is an interpretation of that instant for a particular place. The same timestamp becomes a different date and time in Kolkata, London, and New York, because each place applies its own offset from UTC. The timestamp does not change; only the display changes. Much of the confusion around timestamps comes from treating the display as if it were the value itself, and then being surprised when two correct displays disagree.
Worked example
| Reading | Time | What it shows |
|---|---|---|
| As seconds since the epoch | 1700000000 | One instant, three displays |
| UTC | 14 November 2023, 22:13:20 | The reference reading |
| Kolkata (UTC + 5:30) | 15 November 2023, 03:43:20 | Same instant, next day |
| New York (UTC – 5:00) | 14 November 2023, 17:13:20 | Same instant, earlier in the day |
| Rule | Offsets are not always whole hours, and they change with daylight saving | A converter removes the arithmetic and the guesswork |
Take the timestamp 1700000000. Interpreted as seconds since the epoch, it is 14 November 2023 at 22:13:20 UTC. In Kolkata, which is 5 hours 30 minutes ahead of UTC, the same instant displays as 15 November 2023 at 03:43:20. In New York, which was 5 hours behind UTC on that date, it displays as 14 November 2023 at 17:13:20. All three displays describe the same instant. If a log in Kolkata and a log in New York show different times for the same event, neither is necessarily wrong; they are simply showing the same timestamp in different zones.
This is also why converting in your head is unreliable. Offsets are not always whole hours, as the 30-minute offset in India shows, and offsets change with daylight saving time in many regions. A converter tool removes the arithmetic and the guesswork, and it shows the UTC reading alongside the local reading so you can check both.
Confirm the unit before comparing values. Unix APIs commonly use seconds, while JavaScript Date values use milliseconds
Confirm the unit before comparing values. Unix APIs commonly use seconds, while JavaScript Date values use milliseconds. A seconds value from 2026 has ten digits, while the same instant in milliseconds has thirteen digits, because it is one thousand times larger. If you compare a seconds value with a milliseconds value as if they were the same unit, the results will be wildly wrong: the milliseconds value will look like a date tens of thousands of years in the future, and the seconds value will look like a date in 1970 when read as milliseconds.
Before you compare, convert, or store a timestamp, check the unit. Count the digits as a quick sanity check, and confirm against the documentation of the system that produced the value. When you convert, multiply or divide by 1000 exactly once, and double-check the result by converting it back. Some systems also use microseconds or nanoseconds, so do not assume that a 16- or 19-digit value is a mistake; it may be a finer unit that needs its own conversion.
Use UTC when communicating an instant across systems. Convert to local time only for display
Use UTC when communicating an instant across systems. Convert to local time only for a human-facing display or a workflow that explicitly requires local time. Storing and exchanging UTC keeps every system on the same reference, and it avoids a whole class of errors where a value was written in one zone and read in another. Local time is for people: a calendar view, a schedule, a report heading, or a support conversation where the reader needs to see the time as it felt in their own location.
When you do display local time, always show which zone and offset were used, for example IST (UTC+05:30). A bare time like 03:43 with no zone is ambiguous, because the same reading occurs in many places at different instants. Including the offset makes the display checkable: anyone can convert it back to UTC and confirm it matches the stored timestamp.
Daylight saving time and other local-time traps
Local time is not a simple fixed offset. Many regions shift their clocks forward and back once a year for daylight saving time. That creates two kinds of awkward hour. When clocks go forward, an hour of local time never happens; a time in that gap is not a real instant. When clocks go back, an hour of local time happens twice, so a reading in that hour is ambiguous unless the offset is recorded. A system that stores local time without an offset cannot tell which of the two repeated hours an event belonged to.
UTC has no such shifts, which is another reason to store UTC and convert only at the edge. If a workflow genuinely needs local time, such as a daily report that runs at midnight in a specific city, record the zone name, the offset, and the UTC value together. That way the record stays interpretable even if the region changes its daylight saving rules later, which does happen from time to time.
When diagnosing a mismatch, record the raw value, the unit, the time zone, and the formatting rule
When diagnosing a mismatch, record the raw value, the unit, the time zone, and the formatting rule used by each system. A useful comparison note looks like this: System A recorded 1700000000, seconds, stored as UTC. System B displayed 15 November 2023, 03:43:20, Asia/Kolkata, UTC+05:30. With those four facts on both sides, the comparison becomes arithmetic instead of guesswork. Without them, you are left debating which display is right when both may be.
Also check how each system formats dates. Some systems show month before day, some show day before month, and some use 12-hour clocks without an AM or PM marker. A value that looks like a mismatch can turn out to be a formatting difference on top of a correct instant. Comparing UTC readings first, then local readings, keeps the two questions separate.
A short checklist for logs and APIs
- Store and exchange instants as UTC timestamps, and record the unit explicitly.
- Convert to local time only at display, and always show the zone and offset with the result.
- Confirm seconds versus milliseconds before comparing values from different systems.
- Record the raw value alongside any formatted display, so the comparison can be re-checked later.
- Test with an instant near a daylight saving change, so repeated or missing local hours do not surprise you.
- When two systems disagree, compare their UTC readings first; only then compare their local displays.
Limitations
Timestamps are precise about instants, but they do not capture everything a reader might need. A timestamp does not record which calendar or zone a person was using, how the event should be grouped into a local business day, or what the value means in context. It also does not fix clock problems: if a server clock was wrong, the timestamp faithfully records the wrong time. Very old or very distant dates can run into range limits in some systems; the best-known example is the Year 2038 problem for signed 32-bit seconds counters, which is why modern systems use wider types. Finally, Unix timestamps ignore leap seconds, so they are a practical convention for ordering and comparing events, not a perfect model of astronomical time. For most logging and API work these limits are manageable, as long as they are understood.
Use the related tool carefully
This guide is paired with a browser-only utility. The tool is a practical aid for small examples and inspection; it is not a substitute for application testing, a formal data pipeline, or professional review where the decision has higher consequences. For sensitive logs, remove personal data before converting, or use a local tool on your own machine.
Open the related Unix Timestamp Converter
Related tools in this category
Frequently asked questions
What is a Unix timestamp?
It is the number of seconds since 1 January 1970 at 00:00:00 UTC, not counting leap seconds. The value names a single instant, independent of time zone. A displayed date is that instant converted into a particular zone.
Why do two systems show different times for the same event?
Usually because they display the same instant in different time zones, or because one uses seconds and the other uses milliseconds. Compare the UTC readings and the units first. If those agree, the displays are two correct views of one instant.
Should I store local time or UTC in a database?
Store UTC, plus the unit, and convert to local time only when displaying. Storing local time without an offset makes the record ambiguous, especially around daylight saving changes, and makes comparisons between systems unreliable.
How do I tell seconds from milliseconds?
Count the digits: a current timestamp in seconds has ten digits, while the same instant in milliseconds has thirteen, because it is one thousand times larger. Confirm against the producing system documentation, and verify any conversion by converting the result back.
Sources
- https://www.rfc-editor.org/rfc/rfc3339
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
Try a Tool
Free, in your browser — no sign-up.
- .htaccess Generator Open tool →
- Age Calculator Open tool →
- Angle Converter Open tool →
- API Tester Open tool →
- ASCII Converter Open tool →
- Base64 Encoder and Decoder This tool converts text to the Base64 representation used in many transport and test contexts, and it reverses Base64 text back into Unicode text when the input is valid. Open tool →
Related Articles
How to Format XML So It Is Easy to Read
Learn how to format XML so it is easy to read: consistent indentation, one element per line, matched tags, unchanged data, and…
Read article →How to Build a Query String Without Breaking Your Link
Build a query string without breaking your link. Learn ?key=value, the & separator, encoding, a worked example, and why secrets stay out…
Read article →How to Convert Base64 Back to an Image
Learn how to convert Base64 back to an image, read a data URI, decode a 1 by 1 PNG example, check the…
Read article →