Unix Timestamps and Time Zones: A Developer Guide
6 min read · Published 1 November 2026 · Updated 2 November 2026
Dates and times look simple until two systems disagree about them. A Unix timestamp is the standard way to avoid that: a single number that means the same moment everywhere on Earth. This guide explains what it counts, the bugs that most often appear when you use it, and how to handle time zones correctly.
In this guide
What a Unix timestamp is
A Unix timestamp (also called epoch time or POSIX time) is the number of seconds that have passed since 00:00:00 UTC on 1 January 1970, known as the epoch. For example, 1700000000 is 22:13:20 UTC on 14 November 2023. In Vietnam (UTC+7) that same moment is 05:13:20 on 15 November 2023. The number is identical for everyone; only the way it is displayed depends on the time zone.
Seconds, milliseconds and more
Different systems count in different units. Classic Unix tools, many databases and JWT claims use seconds, which currently gives a 10-digit number. JavaScript (Date.now()), Java and many APIs use milliseconds, giving 13 digits. Some systems use microseconds (16 digits) or nanoseconds (19 digits). When a converted date shows 1970, or a year tens of thousands in the future, the usual cause is a mix-up of seconds and milliseconds, a factor of 1,000.
- 10 digits: seconds (for example 1700000000).
- 13 digits: milliseconds (for example 1700000000000).
- 16 digits: microseconds. 19 digits: nanoseconds.
Why use timestamps at all
- No ambiguity. A timestamp is always UTC, so it does not depend on the server's or user's location.
- Easy arithmetic. The difference between two moments is a subtraction, and adding 86,400 seconds moves forward one day (not counting changes to clock time).
- Compact and sortable. A number is smaller than a formatted string and sorts correctly.
Time zones and daylight saving time
Store and transmit moments in UTC, and convert to a local time zone only when you show them to a person. Vietnam uses UTC+7 all year and has no daylight saving time, but many countries shift their clocks, so a local day can be 23 or 25 hours long. Never calculate "tomorrow" by adding 24 hours to a local time. Use a date library or the platform's time zone support, and refer to zones by name (for example Asia/Ho_Chi_Minh), not by a fixed offset.
ISO 8601 for readable dates
When a date must be written as text, ISO 8601 is the safest format. 2026-11-01T10:30:00Z means 10:30 UTC (the Z stands for zero offset), and 2026-11-01T17:30:00+07:00 is the same moment written with an offset. It sorts alphabetically in time order and is understood by virtually every language and database.
The Year 2038 problem
Some older systems store the timestamp in a signed 32-bit integer, whose largest value is 2,147,483,647. That second is 03:14:07 UTC on 19 January 2038; one second later the value overflows to a negative number and the date jumps back to 1901. Modern systems use 64-bit values, which last for hundreds of billions of years, but embedded devices, old databases and file formats can still be affected.
Other things that catch people out
- Unix time ignores leap seconds. Every day has exactly 86,400 seconds in Unix time.
- JavaScript months are zero-based: new Date(2026, 0, 1) is 1 January, not 1 February.
- Parsing a date string without a time zone may be treated as local time in one environment and UTC in another. Always include the offset or Z.
- Timestamps before 1970 are negative numbers, which some libraries do not accept.
- A "start of day" or "end of day" boundary depends on the user's time zone, so compute it in that zone and convert to a timestamp afterwards.
A short checklist
- Decide whether your API uses seconds or milliseconds and document it.
- Store UTC, convert for display.
- Use ISO 8601 with an offset when exchanging dates as text.
- Use named time zones, never hard-coded offsets, when daylight saving matters.
- Test around daylight saving changes and at the end of months and years.
Converting in code
Note the multiplication by 1000 in JavaScript: its Date works in milliseconds, while the timestamp here is in seconds. Also be aware that some functions, such as MySQL FROM_UNIXTIME, display the result in the session time zone, so the same timestamp can look different on two servers.
Common conversions
// JavaScript
new Date(1700000000 * 1000).toISOString(); // "2023-11-14T22:13:20.000Z"
Math.floor(Date.now() / 1000); // current time in seconds
# Python
from datetime import datetime, timezone
datetime.fromtimestamp(1700000000, tz=timezone.utc)
-- PostgreSQL
SELECT to_timestamp(1700000000);
-- MySQL
SELECT FROM_UNIXTIME(1700000000);One moment, many local times
The timestamp 1700000000 is a single instant. Here is how it reads in several places:
- UTC and London: 14 November 2023, 22:13:20.
- Vietnam (UTC+7): 15 November 2023, 05:13:20.
- Tokyo (UTC+9): 15 November 2023, 07:13:20.
- New York (UTC−5 in November): 14 November 2023, 17:13:20.
Frequently asked questions
- What does the timestamp 0 mean?
- It is the epoch itself: 00:00:00 UTC on 1 January 1970.
- Does a Unix timestamp depend on the time zone?
- No. It counts seconds since the epoch in UTC, so it is the same everywhere. Only the displayed date and time depend on the time zone.
- Why do some timestamps have decimals?
- The fractional part holds fractions of a second, for example 1700000000.123. Many systems prefer an integer number of milliseconds instead.
- Is Unix time the same as UTC?
- Almost. Unix time counts every day as exactly 86,400 seconds and ignores leap seconds, so it can differ from strict UTC by a few seconds in the way leap seconds are handled.
Sources and further reading
Try it yourself: Unix Timestamp & Time Zone Converter runs in your browser, free and with no sign-up.