The last-digit trick of Unix time

A cute trivia about the last digit of Unix timestamp

  ·  2 min read

The Unix timestamp represents the number of seconds since the Unix epoch of 1970-01-01 00:00:00 UTC ignoring leap seconds. Have a look at the following table of Unix timestamps and UTC date time:

Unix timestampUTC date time
17321148722024-11-20 15:01:12 UTC
16238475942021-06-16 12:46:34 UTC
15049328172017-09-09 04:53:37 UTC
16874052632023-06-22 03:41:03 UTC
14173294852014-11-30 06:38:05 UTC

Notice a pattern? The last digit of the Unix timestamp seems to always equal the last digit of the seconds part. For example, the last digit of 1623847594 is 4, and the corresponding UTC date time string is 2021-06-16 12:46:34, which ends with a 4.

Why is this true?

Let \(s \in \mathbf{Z}\) be the number of seconds since the Unix epoch. Since \(s = 0\) corresponds to exactly 1970-01-01 00:00:00 UTC, and there are 60 seconds per minute (ignoring leap seconds), the seconds part of any Unix timestamp is simply \(s \bmod 60\). The last digit of that is therefore \((s \bmod 60) \bmod 10\). On the other hand, the last digit of the Unix timestamp is \(s \bmod 10\).

The original claim is therefore \[ (s \bmod 60) \bmod 10 = s \bmod 10, \] or equivalently, \[ s \bmod 60 \equiv s \pmod{10} \] which is equivalent to saying 10 divides \(\left(s - s \bmod 60\right)\). To prove this statement, write \(s = 60q + r\) by Euclidean division, where \(q, r \in \mathbf{Z}\) where \(0 \le r < 60\). Note that \(r = s \bmod 60\). Then \[ s - s \bmod 60 = 60 q + r - r = 60 q. \] Clearly, 10 divides \(\left(s - s \bmod 60\right)\), as required.