Unix Timestamp & Epoch Converter
Convert between Unix timestamps and human-readable dates. Copy-paste Python, JavaScript, and Pandas code snippets below.
Current Unix Timestamp (seconds)
1785241652
Python Code Snippets
Unix timestamp → datetime (stdlib)
import datetime
# Seconds since epoch → UTC datetime
ts = 1700000000
dt_utc = datetime.datetime.utcfromtimestamp(ts)
print(dt_utc) # 2023-11-14 22:13:20
# With timezone awareness (recommended)
dt_aware = datetime.datetime.fromtimestamp(ts, tz=datetime.timezone.utc)
print(dt_aware.isoformat()) # 2023-11-14T22:13:20+00:00
datetime → Unix timestamp
import datetime
dt = datetime.datetime(2024, 1, 15, 12, 0, 0, tzinfo=datetime.timezone.utc)
unix_ts = int(dt.timestamp())
print(unix_ts) # 1705320000
# From string
dt = datetime.datetime.strptime("2024-01-15 12:00:00", "%Y-%m-%d %H:%M:%S")
dt = dt.replace(tzinfo=datetime.timezone.utc)
print(int(dt.timestamp()))
Pandas: column of Unix timestamps → datetime
import pandas as pd
df = pd.DataFrame({"ts": [1700000000, 1705320000, 1710000000]})
# Seconds
df["datetime"] = pd.to_datetime(df["ts"], unit="s", utc=True)
# Milliseconds
df["datetime_ms"] = pd.to_datetime(df["ts_ms"], unit="ms", utc=True)
# Convert to a specific timezone
df["datetime_chile"] = df["datetime"].dt.tz_convert("America/Santiago")
print(df.head())
Pandas: datetime column → Unix timestamp
import pandas as pd
df = pd.DataFrame({"date": pd.to_datetime(["2024-01-15", "2024-03-01"])})
df["date"] = df["date"].dt.tz_localize("UTC") # make tz-aware first
df["unix"] = df["date"].astype("int64") // 10**9 # nanoseconds → seconds
print(df)
JavaScript Code Snippets
Unix → Date object
const ts = 1700000000;
// JS uses milliseconds
const date = new Date(ts * 1000);
console.log(date.toISOString()); // "2023-11-14T22:13:20.000Z"
console.log(date.toUTCString()); // "Tue, 14 Nov 2023 22:13:20 GMT"
console.log(date.toLocaleString()); // locale-specific
Date → Unix timestamp
const date = new Date("2024-01-15T12:00:00Z");
const unixSeconds = Math.floor(date.getTime() / 1000);
console.log(unixSeconds); // 1705320000
// Current timestamp
const nowUnix = Math.floor(Date.now() / 1000);
SQL Snippets
PostgreSQL
-- Unix timestamp → timestamptz
SELECT to_timestamp(1700000000);
-- timestamptz → Unix
SELECT EXTRACT(EPOCH FROM NOW())::BIGINT;
-- Convert a column
SELECT to_timestamp(created_at_unix) AT TIME ZONE 'America/Santiago'
FROM events;
MySQL / MariaDB
-- Unix → datetime
SELECT FROM_UNIXTIME(1700000000);
-- datetime → Unix
SELECT UNIX_TIMESTAMP(NOW());
What is a Unix timestamp?
A Unix timestamp (also called epoch time or POSIX time) is the number of seconds that have elapsed since January 1, 1970 00:00:00 UTC — a reference point known as the Unix epoch. It is an integer, timezone-independent, and can represent any moment in time with a single number. Most systems store timestamps in seconds; JavaScript and some databases use milliseconds (multiply seconds by 1,000).
Common Unix timestamp reference values
| Date (UTC) | Unix timestamp (seconds) |
|---|
| January 1, 1970 00:00:00 | 0 |
| January 1, 2000 00:00:00 | 946684800 |
| January 1, 2024 00:00:00 | 1704067200 |
| January 1, 2025 00:00:00 | 1735689600 |
| January 1, 2038 00:00:00 | 2145916800 |
Why use Unix timestamps?
Unix timestamps are the standard for time storage in software because they are timezone-independent— the same integer represents the same moment everywhere. They sort correctly as plain integers, compare with simple arithmetic, and fit in a single 32-bit or 64-bit integer column in a database. APIs, logs, and event systems use them to avoid ambiguity from daylight saving time, locale formats (MM/DD vs DD/MM), and timezone offsets.
Frequently asked questions
What is the difference between Unix time in seconds and milliseconds?
Most Unix timestamps count seconds since the epoch. JavaScript's Date.now() and many browser/Node.js APIs return milliseconds — 1,000× larger. A timestamp > 1e12 is almost certainly in milliseconds. Divide by 1000 to get seconds, or multiply seconds by 1000 to get milliseconds.
What happens at the Unix timestamp 2147483647?
On January 19, 2038 at 03:14:07 UTC, 32-bit signed integers overflow — this is the "Year 2038 problem". Systems using 32-bit Unix timestamps will wrap to a negative number. 64-bit timestamps (supported by modern systems) won't overflow for ~292 billion years.
How do I convert a Unix timestamp to a specific timezone?
Use datetime.fromtimestamp(ts, tz=pytz.timezone("America/New_York")) in Python, or new Date(ts * 1000).toLocaleString("en-US", { timeZone: "America/New_York" }) in JavaScript.