Convert Unix Timestamp to Date

Convert a Unix timestamp to a human-readable date.

Code

Python
from datetime import datetime

ts = 1709827200  # Unix timestamp
dt = datetime.fromtimestamp(ts)
print(dt.strftime("%Y-%m-%d %H:%M:%S"))

# Or with timezone
from datetime import timezone
dt_utc = datetime.fromtimestamp(ts, tz=timezone.utc)
print(dt_utc)

Line-by-line explanation

Expected output

2024-03-07 00:00:00

Related snippets

Related DuskTools