Python Timestamp
Reliable Unix timestamp patterns in Python for backend services and scripts.
What is this tool?
This page is a Python-oriented timestamp reference that covers generation, parsing, and UTC-safe formatting patterns.
How to use it
Use the examples to standardize timestamp handling in CLI scripts, web services, and ETL jobs. Prefer timezone-aware datetime objects for correctness.
Examples
Python
import time
from datetime import datetime, timezone
# current unix seconds
seconds = int(time.time())
# utc datetime
utc_now = datetime.now(timezone.utc)
# from timestamp
readable = datetime.fromtimestamp(seconds, timezone.utc).isoformat()Common use cases
- Service event timestamps in APIs.
- ETL pipeline ingestion ordering.
- Automated reporting windows.
FAQ
- Should I use time.time or datetime.now?
- Use time.time for raw Unix timestamps and datetime for timezone-aware formatting workflows.
- How do I get UTC in Python?
- Use datetime.now(timezone.utc) for explicit UTC-aware datetime objects.