How to Convert a Unix Timestamp to a Date (and Back)

Short answer
A Unix timestamp counts the seconds since 1 January 1970, 00:00:00 UTC. Divide by 86,400 to get days, or let code do it: 1800000000 is 15 January 2027, 08:00:00 UTC, which is 03:00 the same morning in Toronto (UTC−5). If the number has 13 digits it is in milliseconds, so divide by 1,000 first.
Unix timestamps appear in log files, APIs, databases, cookies and spreadsheets exported from apps. They are compact and easy for computers to compare, but a number like 1798761600 means nothing to a person until it is converted. This guide explains what the number counts, how to convert it in both directions, and the traps around milliseconds and time zones. You can paste any value into the Unix timestamp converter to check.
What a Unix timestamp is
The POSIX standard defines “seconds since the Epoch” as the number of seconds that have passed since 00:00:00 UTC on 1 January 1970, counting every day as exactly 86,400 seconds. Leap seconds are not counted, which is why the arithmetic stays simple: every day adds exactly 86,400 to the number. Times before 1970 are negative numbers.
Because the count is tied to UTC, a timestamp is the same everywhere in the world at the same instant. Only the way it is displayed changes with your time zone.
Checked examples
| Timestamp (seconds) | UTC | Toronto (local time) |
|---|---|---|
| 0 | 1 Jan 1970, 00:00:00 | 31 Dec 1969, 19:00:00 (UTC−5) |
| 1,000,000,000 | 9 Sep 2001, 01:46:40 | 8 Sep 2001, 21:46:40 (UTC−4) |
| 1,700,000,000 | 14 Nov 2023, 22:13:20 | 14 Nov 2023, 17:13:20 (UTC−5) |
| 1,798,761,600 | 1 Jan 2027, 00:00:00 | 31 Dec 2026, 19:00:00 (UTC−5) |
| 1,800,000,000 | 15 Jan 2027, 08:00:00 | 15 Jan 2027, 03:00:00 (UTC−5) |
| 2,147,483,647 | 19 Jan 2038, 03:14:07 | 18 Jan 2038, 22:14:07 (UTC−5) |
The September 2001 row shows Toronto on daylight time (UTC−4); the others fall in standard time (UTC−5). The same timestamp can land on a different calendar date depending on where you read it.
Converting by hand
You rarely need to, but doing it once shows how the number works. Take 1,800,000,000:
- Divide by 86,400 seconds per day: 1,800,000,000 ÷ 86,400 = 20,833 whole days, with 28,800 seconds left over.
- 28,800 seconds ÷ 3,600 = 8 hours, so the time is 08:00:00 UTC.
- Count 20,833 days forward from 1 January 1970, allowing for leap years, and you reach 15 January 2027.
Step 3 is where code is far more reliable than a person, which is why every language has a built-in function.
Converting in code and spreadsheets
- JavaScript:
new Date(1800000000 * 1000).toISOString()gives2027-01-15T08:00:00.000Z. JavaScript dates use milliseconds, hence the × 1000. Back the other way:Math.floor(Date.now() / 1000). - Python:
datetime.fromtimestamp(1800000000, tz=timezone.utc)from thedatetimemodule. For a local zone, passZoneInfo("America/Toronto")instead of UTC. Back:int(dt.timestamp()). - Excel and Google Sheets:
=A1/86400 + DATE(1970,1,1), then format the cell as a date and time. The result is in UTC; add or subtract hours ÷ 24 for a local zone, remembering daylight saving time. - Command line (Linux):
date -u -d @1800000000.
Seconds or milliseconds?
Count the digits. Timestamps for dates between 2001 and 2286 have 10 digits in seconds and 13 digits in milliseconds. JavaScript, Java and many web APIs use milliseconds; Unix tools, PHP and most databases use seconds. If a conversion lands tens of thousands of years in the future, or in January 1970, you almost certainly used the wrong unit.
Time zones and UTC
Convert to UTC first, then to a local zone using a named time zone such as America/Toronto or Asia/Kolkata, not a fixed offset. Named zones come from the IANA time zone database, which records when each region changes its clocks. A fixed “−5” would be wrong for Toronto during summer daylight time.
The year 2038 problem
Older systems store the timestamp as a signed 32-bit integer. Its largest value is 2,147,483,647, which is 03:14:07 UTC on 19 January 2038. One second later the number overflows and can wrap to a date in December 1901. Modern operating systems and languages use 64-bit time values, but embedded devices, old file formats and some databases may still be affected, so it is worth checking any system expected to run beyond 2037.
Common mistakes
- Treating milliseconds as seconds, or the other way round.
- Reading a UTC result as local time, which shifts the time by several hours and sometimes the date.
- Using a fixed offset instead of a named zone, which breaks around daylight saving changes.
- Storing local time as a timestamp. Timestamps should always mean UTC.
Frequently asked questions
What is a Unix timestamp?
The number of seconds since 00:00:00 UTC on 1 January 1970, not counting leap seconds. It is the same number everywhere in the world at the same instant.
How do I convert a Unix timestamp to a date in Excel?
Use =A1/86400 + DATE(1970,1,1) and format the cell as a date. The result is in UTC; adjust by hours ÷ 24 for your time zone.
Is my timestamp in seconds or milliseconds?
For dates since 2001, 10 digits means seconds and 13 digits means milliseconds. Divide a millisecond value by 1,000 to get seconds.
What is Unix timestamp 0?
00:00:00 UTC on 1 January 1970, which was 7 pm on 31 December 1969 in Toronto.
What happens in 2038?
Systems that store time as a signed 32-bit number overflow after 2,147,483,647, which is 03:14:07 UTC on 19 January 2038. 64-bit systems are not affected.
Do Unix timestamps include leap seconds?
No. POSIX time counts every day as exactly 86,400 seconds.
Sources
- The Open Group, POSIX Base Definitions, section 4.16 Seconds Since the Epoch (checked 30 November 2026)
- MDN Web Docs: JavaScript Date (milliseconds since the epoch) (checked 30 November 2026)
- IANA: Time Zone Database (checked 30 November 2026)
Note: General technical information. All example conversions were computed with Python's datetime and zoneinfo modules on 30 November 2026.