Unix Timestamp in Python

Python's time module gives you the current Unix timestamp as a float (seconds with decimal precision). Use int() to truncate to whole seconds.

Code Examples

Current timestamp (seconds)

import time
int(time.time())

The classic way. time.time() returns a float; int() truncates to whole seconds. Works in Python 2 and 3.

Current timestamp (milliseconds)

import time
int(time.time() * 1000)

Multiply by 1000 for millisecond precision — useful when interfacing with JavaScript or Java APIs.

Using datetime module

from datetime import datetime, timezone
int(datetime.now(timezone.utc).timestamp())

The datetime approach. Always pass timezone.utc to avoid local-time ambiguity when computing the timestamp.

Convert timestamp to datetime

from datetime import datetime, timezone
datetime.fromtimestamp(timestamp, tz=timezone.utc)

Convert a Unix timestamp back to a timezone-aware datetime object. Omitting tz uses local time, which can cause bugs.

pandas (data science)

import pandas as pd
pd.Timestamp.now().timestamp()

In pandas, Timestamps are timezone-aware and convert cleanly to Unix time.

Note

Python's time.time() returns seconds as a float, not milliseconds. This is the opposite of JavaScript's Date.now(). Be careful when passing timestamps between Python backends and JS frontends.

Main Epoch Converter

Use the homepage when you need epoch to date, date to epoch, or a full epoch converter

This Python guide shows how to create and parse Unix timestamps in code. If your next step is broader search intent like epoch converter, epoch to date, epoch time to date, or unix epoch converter, jump back to the live homepage tools to paste a raw Unix value, auto-detect seconds versus milliseconds, and copy the readable answer instantly.

Related Tools

More free tools for developers debugging timestamps, schedules, and text changes.