An Introduction to Unix Time and the Year 2038 Problem

+8

Introduction

Have you ever wondered how computers keep time? How can computers know what date and time it is by looking at just a single number? What exactly will happen in the year 2038, and why is it going to happen? And finally, how does the future of Unix time look like? If you want to have these questions answered, look no further! This blog will explain to you what Unix time is, how it is stored inside a computer, what exactly is wrong with the year 2038, and what the future of Unix time probably looks like. Without further ado, let's get started!

What Is Unix Time?

Unix time is a timekeeping system that is widely used by computers as well as web servers. It was designed to standardize the timekeeping method used in computers. Unix time is defined as the number of seconds since the "Epoch", which is arbitrarily set to midnight UTC, January 1, 1970. The number also excludes any leap seconds that have been added since the "Epoch". For example, in Unix time, "June 1, 1970 at 00:00:00 UTC" would be represented as "13,046,400", since 13,046,400 seconds (151 days) had already passed since the Epoch.

The reason why you can see human-readable dates and times on computers is that the computer uses an internal algorithm to convert the Unix timestamp into numbers/words representing the year, month, day, hour, minute, and second.

What's Wrong with Year 2038 Then?

To understand why the year 2038 problem is a thing, you must first understand how an integer is stored inside a computer. Unix timestamps are usually stored in computers as signed 32-bit integers (a "bit" is a binary digit, which can be either 0 or 1). One of these 32 bits is used as an indicator for the sign (positive/negative) of the number, and the rest are used to store the actual number. When using 31 bits to store an integer, the largest representable number is 231 − 1, or 2,147,483,647. This number as a Unix timestamp corresponds to 2,147,483,647 seconds since the Epoch, which translates to January 19, 2038 at 03:14:07 UTC. If this number was to be incremented (go up by one), it would cause integer overflow, meaning the 31 bits would not be enough for storing the integer (in this case the timestamp) anymore. And that could lead to devastating consequences, considering how widely computers are used nowadays.

How Can We Fix It?

The fix is simple - just switch to 64-bit integers instead of 32-bit ones! In fact, this has already been done in many computers and devices around the world. Technically though, it will still overflow eventually, but that's going to take a very, very long time, so long that it is well beyond the lifespan of the Earth: the Sun will die in 5 billion years, while it will take over 200 billion years for a 64-bit Unix timestamp to overflow!

So Will There Be Any Other Problems in the Future?

Sadly, yes. A few years from now the year 2038 problem may not be a thing anymore, but there's still going to be issues in the far future. Thanks to the Earth's slowing rotation, we will have to insert more and more leap seconds into our clocks if we don't wish to change the length of a second. Unix timestamps, however, are not incremented and remain unchanged during a leap second, which would result in more and more ambiguities and other leap second related problems occurring, some of which have already been felt. But those issues are beyond the topic of this blog.

Thanks for reading, and if you are worrying about the year 2038 problem, don't, since it's a widely discussed issue in the field of computer science and many people are now working to address it!

+2
Level 57
May 22, 2022
Very informative! I wonder if my Chromebook has 64 or 32?
+4
Level 78
May 22, 2022
Intersting. Is there a way of checking if a device has 32 or 64 ?

Although my computer will probably not last til 2038, a situation that I myself am in, I may not last that long either. (I'll be 76 then and probably eating food from a spoon held by a nurse that I can't remember the name of.)

+1
Level 50
May 22, 2022
I don't think that's possible without using a programming language (like C or C++). Also if you're on Windows it probably won't affect you since I've read somewhere that Windows time will not overflow till 2184
+2
Level 78
May 22, 2022
I'm using Windows 10 so safe then.

2184....mmmm....I will be 222 years old by then. I think I shall be just a memory on a geneology website by then.

+3
Level 43
May 22, 2022
hopefully we have toowise and akj for more 222 years
+2
Level 75
May 24, 2022
On my computer at least I can check by right clicking "Computer" then going into "Properties". I am on Win7 though so I can't say for sure whether it works for others.
+1
Level 50
May 24, 2022
It works for Windows 10 as well, and I do appreciate the fact that you're still using a system that's something like 13 years old

Previously I thought it was only possible by defining a variable inside a programming language and then checking its size

+1
Level 75
May 24, 2022
Well I only use it because my computer was a hand-me-down with a pirated copy of Win7 so I can't upgrade.
+2
Level 63
May 22, 2022
Very interesting blog, as always! I've never known or heard about this problem apart from the 1999 date error. I think most people have a Windows computer though so it won't be a problem for many.
+2
Level 43
May 22, 2022
I saw that on my mom’s phone when I was like... 5 years old. I was scared because I thought my cousin would never celebrate birthday anymore (October doesn’t appear in the 2038 glitch) lol.

Your blogs convey such information, and lots of sources!

+2
Level 74
May 23, 2022
Nice & well explained!
+1
Level 60
Jan 10, 2024
I was just reading random blogs that were interesting to me. Imagine my surprise when all 4 are by you. Great job! I would recommend explaining the part about the largest representable number more. It might be clearer to explain that the largest number would be 2^30 + 2^29 + ... + 2^0 and that can be simplified to 2^31 - 1.