Python Timestamp Guide

Python code examples for Unix timestamps. Get current time, convert between datetime and epoch, format dates, and parse strings with time module.

Built by Michael Lip

Frequently Asked Questions

How do I get the current Unix timestamp in Python?

Use import time; timestamp = int(time.time()). This returns the current epoch in seconds. For milliseconds, use int(time.time() * 1000).

How do I convert a timestamp to a datetime in Python?

Use from datetime import datetime; dt = datetime.fromtimestamp(1712000000). For UTC, use datetime.utcfromtimestamp() or datetime.fromtimestamp(ts, tz=timezone.utc).

How do I convert a datetime to a timestamp in Python?

Use dt.timestamp() on a datetime object to get epoch seconds. For example: from datetime import datetime; ts = int(datetime(2025, 4, 2).timestamp()).

How do I format a date in Python?

Use strftime: dt.strftime('%Y-%m-%d %H:%M:%S'). Common codes: %Y (4-digit year), %m (month), %d (day), %H (24h hour), %M (minute), %S (second).

What is the difference between time.time() and datetime.now()?

time.time() returns a float of epoch seconds. datetime.now() returns a datetime object. Use time.time() for simple timestamps and datetime for date arithmetic and formatting.

How It Works

This tool runs entirely in your browser using vanilla JavaScript. No data is sent to any server. All conversions and calculations happen locally on your device, ensuring complete privacy.

EpochPilot uses the browser's built-in Intl.DateTimeFormat API and the IANA timezone database provided by your operating system. This means timezone conversions are always accurate, including Daylight Saving Time transitions.

Related Tools

Privacy

Everything runs locally in your browser. No timestamps, dates, or personal data are transmitted to any server. The source code is open on GitHub.

Contact

EpochPilot is built and maintained by Michael Lip. For questions or feedback, email [email protected].

📊 Format data from our Timestamp Format Encyclopedia — 93 formats documented