TLDR Web Dev · OPINIONS & ADVICE

A PYTHON EPOCH TIMESTAMP TIMEZONE TRAP

nerderati.com6 min read

Summary from the TLDR Web Dev newsletter

Python's datetime module can cause confusion when converting between timestamps and datetime objects due to timezone issues. The time.time() function returns a timestamp relative to epoch (UTC), while datetime.datetime.now() returns a timezone-naive object in the local timezone. This discrepancy can lead to incorrect results when converting timestamps back to datetime objects on systems with non-UTC timezones.