📘 Unix Timestamp Guide

Epoch time explained, with copy-ready code for 5 languages

← Back to Timestamp Converter

What is a Unix timestamp?

A Unix timestamp (epoch time) is the number of seconds that have passed since 1 January 1970 00:00:00 UTC, ignoring leap seconds. It is timezone-independent, which is why APIs, databases and logs use it instead of formatted dates.

Get the current timestamp

Every language below returns the same value — seconds since the epoch. Use seconds unless the API explicitly asks for milliseconds.

// JavaScript
Math.floor(Date.now() / 1000)

# Python
import time
int(time.time())

// PHP
time();

-- MySQL
SELECT UNIX_TIMESTAMP();

' Excel (A1 holds a date)
=ROUND((A1-DATE(1970,1,1))*86400,0)

Convert a timestamp back to a date

Multiply by 1000 first in JavaScript and other millisecond-based runtimes. Always format in UTC, then convert to the visitor's local time only for display.

// JavaScript
new Date(1700000000 * 1000).toISOString()

# Python
from datetime import datetime, timezone
datetime.fromtimestamp(1700000000, timezone.utc)

// PHP
gmdate('Y-m-d H:i:s', 1700000000);

-- MySQL
FROM_UNIXTIME(1700000000);

10-digit vs 13-digit timestamps

10 digits = seconds (valid until the year 2286). 13 digits = milliseconds, the format used by JavaScript's Date.now() and most JSON APIs. If a date looks like 1970, you probably forgot to divide by 1000; if it looks like year 55000, you forgot to multiply.

Common pitfalls

Never store local-time strings in a database. Watch for the Year 2038 problem on 32-bit systems, and remember that Unix time has no leap seconds — a day is always exactly 86400 seconds.

FAQ

Is a Unix timestamp always in UTC?
Yes. A timestamp is an absolute instant; only the formatted output depends on the timezone.

Why does my timestamp show 1970?
You passed milliseconds to a function that expects seconds, or the value is 0 / empty.

Does daylight saving time change the timestamp?
No. DST only affects how a timestamp is displayed, never the number itself.

Convert a timestamp now →