Date, Time & Calendar • 5 min read

Unix Timestamps and Time Zones: A Practical Guide for Developers

Seconds vs milliseconds, storing UTC, converting for display, daylight saving pitfalls and the 2038 problem, with JavaScript, Python and SQL examples.

Published: 2026-11-11 • Last Updated: 2026-11-11 • By Mohammed Zawwar Hussain

Interactive Online Tools Referenced in this Guide

What a Unix timestamp is

A Unix timestamp is the number of seconds since 1 January 1970 00:00:00 UTC, ignoring leap seconds. It is the same number everywhere on Earth at the same instant, which makes it ideal for storing and comparing times. Time zones only matter when you show the time to a person.

Seconds or milliseconds?

Today a timestamp in seconds has 10 digits (for example 1767225600) and one in milliseconds has 13 (1767225600000). JavaScript's Date.now() returns milliseconds; most Unix tools, PHP and many APIs use seconds. If a converted date lands in 1970 or in the year 58,000, you mixed them up. The Unix Timestamp Converter accepts both.

JavaScript: Math.floor(Date.now() / 1000)
Python: int(time.time())
PostgreSQL: SELECT extract(epoch FROM now());
MySQL: SELECT UNIX_TIMESTAMP();

Store in UTC, display in local time

  • Store instants as UTC timestamps or as timestamp-with-time-zone columns.
  • Store the user's IANA time zone name (such as Asia/Riyadh or Europe/London) separately if you need to show their local time.
  • Convert only at the edge, in the UI or report, using a time-zone database rather than fixed offsets.

Daylight saving time pitfalls

Saudi Arabia (UTC+3), the UAE (UTC+4) and Pakistan (UTC+5) do not observe daylight saving time, but Europe and North America do, on different dates. A meeting at 10:00 Riyadh time is 07:00 in London in winter and 08:00 in summer. Never hard-code "+1 hour" offsets; use the zone name and let the library apply the rules. The Timezone Converter does this for each date you pick.

The year 2038 problem

Systems that store timestamps as signed 32-bit integers overflow at 03:14:07 UTC on 19 January 2038. Use 64-bit integers or native date-time types in new code, and check old databases, embedded devices and file formats that still use 32-bit time.

Seconds, milliseconds and microseconds

The same moment can appear in different units, and mixing them up is the most common timestamp bug:

UnitDigits (2026)ExampleUsed by
Seconds101793750400Unix, PHP time(), Python time.time() (as a float), JWT exp
Milliseconds131793750400000JavaScript Date.now(), Java System.currentTimeMillis()
Microseconds161793750400000000PostgreSQL internals, some logging systems

A date in January 1970 almost always means a seconds value was read as milliseconds; a date far in the future means the opposite.

Converting in code

// JavaScript
const seconds = Math.floor(Date.now() / 1000);
new Date(seconds * 1000).toISOString();

# Python
from datetime import datetime, timezone
datetime.fromtimestamp(1793750400, tz=timezone.utc).isoformat()

-- PostgreSQL
SELECT to_timestamp(1793750400); -- timestamptz
SELECT extract(epoch FROM now());

In Python, always pass tz=timezone.utc; without it, fromtimestamp uses the server's local time zone, which changes when you deploy somewhere else.

Store UTC, display local

The rule that prevents most time bugs: store and compute in UTC (or as Unix timestamps), and convert to a local time zone only when showing a time to a person. Use named IANA zones such as Asia/Riyadh, Asia/Karachi or Europe/London rather than fixed offsets like +03:00, because offsets change with daylight saving and with government decisions.

Saudi Arabia is a convenient zone: UTC+3 all year, with no daylight saving. Do not assume the same for your users abroad. The UK, Europe and most of North America move their clocks twice a year, and those dates differ between them, so a meeting at 16:00 Riyadh time can be at 13:00 or 14:00 in London depending on the week. The Timezone Converter works this out for the date you choose.

The year 2038 problem

Systems that store Unix time in a signed 32-bit integer run out on 19 January 2038 at 03:14:07 UTC, when the counter reaches 2,147,483,647 and wraps to a negative number (a date in 1901). Modern 64-bit operating systems and languages are not affected, but old embedded devices, legacy database columns declared as 32-bit INT, and some file formats are. If you design a database today, use a 64-bit integer or a proper timestamp type.

ISO 8601 for humans and APIs

When a time must be readable, use ISO 8601 with an explicit offset, for example 2026-11-11T19:30:00+03:00 or the UTC form 2026-11-11T16:30:00Z. It sorts correctly as text, every language can parse it, and it never leaves the reader guessing which time zone was meant. Avoid formats like 11/12/2026, which mean 11 December in Europe and November 12 in the United States.

A debugging checklist for time bugs

  1. Print the raw value and count its digits: 10 means seconds, 13 milliseconds.
  2. Check what time zone the server, the database session and the browser think they are in. A database set to UTC and an application server set to Asia/Riyadh shift every naive timestamp by three hours.
  3. Look for "naive" date-times without a zone, such as Python datetime.now() or SQL TIMESTAMP WITHOUT TIME ZONE, and replace them with zone-aware values.
  4. Test around midnight and month ends: a value that is 23:30 on 31 March in UTC is already 1 April in Riyadh.
  5. Test a date during daylight saving in Europe or North America if you have users there.

The Unix Timestamp Converter accepts both seconds and milliseconds, which makes step 1 quick.

Frequently Asked Questions

Is a Unix timestamp affected by time zones? ↓
No. It always counts from midnight UTC on 1 January 1970.
Are leap seconds included? ↓
No. Unix time treats every day as exactly 86,400 seconds.
What format should APIs use? ↓
ISO 8601 strings with an offset, such as 2026-11-11T09:30:00Z, are readable and unambiguous; timestamps are compact. Either works if documented.
Do Unix timestamps include leap seconds? ↓
No. Unix time assumes every day has exactly 86,400 seconds, so leap seconds are not counted. For almost all applications this does not matter.
Is a timestamp the same everywhere in the world? ↓
Yes. A Unix timestamp is the same number at the same moment in every time zone; only its local display differs.
Does the 2038 limit affect JavaScript? ↓
No. JavaScript Date objects store milliseconds in a 64-bit floating-point number and can represent dates up to the year 275760.