The fundamentals of time¶
Time isn’t actually that hard—once you understand a handful of concepts.
The trouble is that most of us learn it backwards: API first.
In Python that usually means the standard library’s datetime module,
figured out by trial and error, without ever forming a clear picture of what a
time value is supposed to represent.
It’s the same way many people use str long before they’ve heard of
Unicode: a rule of thumb like “just use UTF-8” carries you a long way—right up
until something behaves strangely and you have no model to reason with.
“Just use UTC” is that kind of rule, and it fails the same way. The pages below cover the handful of ideas such rules paper over. They’re written to be read in order, starting with the most important distinction of all: exact time versus local time.
A moment on the timeline, or a reading on a clock: not the same thing
The rules that connect the two—and what “timezone” actually means
When the clock says something twice, or skips it entirely
Why “a day later” and “24 hours later” are different questions
Tip
Once you’re comfortable with the fundamentals,
head to the guide to see how whenever puts them into practice.