TimeKit
All Articles
Tech5 min readJuly 5, 2024

How Computers Store Dates and Times

Behind every timestamp is a clever system of counting from a fixed reference point.

To a computer, a date isn't "March 4, 2025." Underneath, it's almost always a single number. Understanding how machines represent time explains a lot about how software behaves.

Counting From a Reference Point

The dominant approach is elegantly simple: pick a fixed moment in history — an epoch — and store any date as the number of time units that have passed since then.

The most famous is the Unix epoch: midnight UTC on January 1, 1970. A timestamp like 1,700,000,000 simply means "1.7 billion seconds after that moment."

Why a Number?

Storing time as a single number has huge advantages: - Comparison is trivial: a later moment is just a bigger number - Arithmetic is easy: subtract two timestamps to get the duration between them - It's timezone-neutral: the number refers to an absolute instant; display formatting handles local time separately

Precision and Size

Different systems count different units: - Seconds since the epoch (classic Unix time) - Milliseconds (JavaScript, Java) - Nanoseconds (high-precision systems)

The size of the storage matters. A 32-bit integer runs out in 2038; modern systems use 64-bit values that last billions of years.

The Timezone Layer

A timestamp itself has no timezone — it's an absolute point in time. The timezone is applied only when displaying the date to a human. The same timestamp shows as 9:00 AM in New York and 2:00 PM in London. This separation of storage from display is a core principle of good date handling.

Why Bugs Happen

Most date bugs come from confusing these layers: - Mixing seconds and milliseconds (off by a factor of 1,000) - Forgetting that a stored timestamp is UTC and displaying it as local time - Assuming every day has exactly 24 hours (DST transitions break this)

The Takeaway

Behind every friendly calendar date is a humble counter ticking up from a fixed point in 1970. Once you understand that a date is "just a number plus a display rule," the behavior of timestamps, time zones, and conversion tools suddenly makes much more sense.

#programming#dates#epoch