Get the latest tech news

Timezone-naive datetimes are one of the most dangerous objects in Python


I primarily yell at code. Well, I look sternly in its general direction, gently urging it to do my bidding.

If you don't specify the tz argument, the timestamp is converted to the local date and time of the platform where the code is executed, and this returned datetime object is timezone-naive. Epoch timestamps are, generally, a decent way to perform relative comparisons between two moments in time that satisfy the two following conditions: The epoch returned by time.time() is, as I previously mentioned, timezone-independent, which means that fromtimestamp() has no clue what to attach to the resulting datetime object.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of python

python

Photo of naive datetimes

naive datetimes

Photo of dangerous objects

dangerous objects

Related news:

News photo

Leaked admin access token to Python, PyPI, and PSF GitHub repos

News photo

Jurigged: Hot Reloading for Python

News photo

Making Python Less Random