How to Think About Time in Programming
Date published: Jun 23, 2025
Time handling is everywhere in software, but many programmers talk about the topic with dread and fear. Some warn about how difficult the topic is to understand, listing bizarre timezone edge cases as evidence of complexity. Others repeat advice like "just use UTC bro" as if it were an unconditional rule - if your program needs precise timekeeping or has user-facing datetime interactions, this advice will almost certainly cause bugs or confusing behavior. Here's a conceptual model for thinking about time in programming that encapsulates the complexity that many programmers cite online.
Absolute Time
Two important concepts for describing time are "durations" and "instants". A duration is like the number of seconds it takes Usain Bolt to finish a 100m race; an instant is like the moment that he crossed the finish line, or the moment he was half-way through the race. The concept of "absolute time" (or "physical/universal time") refers to these instants, which are unique and precisely represent moments in time, irrespective of concepts like calendars and timezones.
Usain Bolt at the Beijing 2008 Olympics (Photo from boston.com)
How can we refer to two instants in a way that describes which instant came first and what the duration is between them? Labeling them like "The instant Usain finished the race" or "The instant Neil Armstrong first stepped on the Moon" doesn't provide this information (it's like how labeling places as "home" or "store" doesn't communicate the distance between them). One way to precisely refer to instants is by their duration from some reference point: the instant Usain crossed the finish line is the instant 9.69 seconds from the reference point when the race starting pistol went off.
Programmers call this reference instant an "epoch" - it's the instant whose number representation is 0 seconds. The epoch could be any instant: Many systems support Unix time, which uses the Unix epoch (Jan 1st, 1970 00:00:00 UTC), but other epochs work too (e.g. Apollo_Time in Jai uses the Apollo 11 rocket landing at July 20, 1969 20:17:40 UTC).
Each row of labels represents the same absolute instants in time, but with different rules for what those labels look like
The importance of an epoch may feel untrue, since we talk about instants in everyday conversation without explicitly stating a reference point, but even in phrases like "last night" or "tomorrow at noon", you're implicitly assuming a reference point of the current moment and talking about an instant that's some number of seconds away from the current moment. It's like how you can say "here" or "there" because of the implicit reference point of your current position.
... continue reading