Current Unix timestamp in Python

import time; print(int(time.time()))

int(time.time()) is the current Unix time in whole seconds. time.time() itself returns a float with a fraction of a second, and int() drops the fraction.

import time

print(time.time())
print(int(time.time()))
print(time.time_ns() // 1_000_000_000)
print(time.time_ns() // 1_000_000)
1792021963.2666938
1792021963
1792021963
1792021963266

That’s Python 3.14 at 2026-10-14T23:52:43Z, the instant the tool below starts from. The tool takes the float as printed: it reads 1792021963.2666938 as 2026-10-14 23:52:43 UTC, keeps the fraction to the microsecond (1792021963.266693) and notes the seventh decimal place it drops. The last line is milliseconds, the unit JavaScript’s Date.now() uses. time.time_ns() (Python 3.7+) returns an exact integer, so dividing it never meets float rounding.

With datetime

from datetime import datetime, timezone

print(int(datetime.now(timezone.utc).timestamp()))
print(datetime.fromtimestamp(1700000000, tz=timezone.utc).isoformat())
print(datetime.fromtimestamp(1700000000))
1792021963
2023-11-14T22:13:20+00:00
2023-11-14 17:13:20

Without tz, fromtimestamp returns a naive datetime on the machine’s clock; this ran with TZ=America/New_York. Python 3.11 added datetime.UTC as a shorter name for timezone.utc.

The naive-datetime trap

A datetime without tzinfo is naive, and .timestamp() takes a naive value to be local time. datetime.utcnow() returns the UTC wall clock as a naive value, so its timestamp is off by the machine’s UTC offset. Same machine, still in New York:

naive = datetime(2023, 11, 14, 22, 13, 20)
aware = datetime(2023, 11, 14, 22, 13, 20, tzinfo=timezone.utc)
print(naive.timestamp())
print(aware.timestamp())
print(round(datetime.utcnow().timestamp() - datetime.now(timezone.utc).timestamp()))
1700018000.0
1700000000.0
14400

The naive value came out 5 hours late (EST in November) and utcnow() 4 hours (EDT in October). The tool agrees: 2023-11-14 22:13:20 read in America/New_York is 1700018000. Python 3.12 deprecated utcnow() and utcfromtimestamp() for this reason, and the run printed a warning on stderr:

DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).

Use datetime.now(timezone.utc) and datetime.fromtimestamp(ts, tz=timezone.utc) instead.

Measuring time

time.time() follows the system clock, which NTP or an administrator can set back. For durations use time.monotonic() or time.perf_counter(), which never go backwards:

start = time.monotonic()
time.sleep(0.25)
print(round(time.monotonic() - start, 2))   # 0.26

Try it in the Unix Timestamp Converter

Current Unix time

Your browser's clock shows the current time here once the page loads.

2026-10-14 23:52:43 UTC (UTC+00:00)

Seconds1792021963.266693
Milliseconds1792021963266.693
ISO 8601 (UTC)2026-10-14T23:52:43.266Z
Day of the weekWednesday
Read asseconds since the epoch
Relative to nownow

The fraction has 7 decimal places, 1 past the microsecond: the seconds and milliseconds stop at microseconds, and the ISO time at milliseconds.

Runs in your browser. Nothing you enter is sent anywhere.