Problem of repetition

1970-01-01 is familiar to developers, and some systems may display the time as 1970-01-01 if their handling of the time is not good enough, so 1970-01-01 is often seen by users.

This situation can be easily repeated when we try to define the time using the following Java code:

Date date = new Date(0);
System.out.println(date);
Copy the code

Printed results:

Thu Jan 01 08:00:00 CST 1970
Copy the code

We can also get some clues from the Java Doc description of the Date constructor:

The constructor accepts the user to specify a number of milliseconds, such as new Date(1000), to obtain an epoch that is 1000 milliseconds away. In Java, the time is 1970, 00:00:00 GMT.

The time stamp

It all started with the birth of the Unix operating system.

In August 1969, Ken Thompson, a programmer at Bell LABS, took advantage of his wife and children’s month-long absence to set out to create a revolutionary new operating system. He developed a version of Unix using the B-compiled language on the aging PDP-7 machine.

Thompson and his colleague Dennis Leach then improved ON B and developed C, rewriting Unix and releasing the new version in 1971.

After Unix was invented, to represent time on Unix, it was necessary to find a way to define a complete, verifiable representation of time that could represent the existence of a piece of data prior to a certain time.

Thus, Unix timestamps were defined by comparing the current time with an “epoch time”, with the number of seconds between them as the timestamp.

To make Unix timestamps last as long as possible, 1971-1-1, the birth date of Unix, was originally defined as “epoch time.”

Timestamp modification

In addition to starting at 1971-1-1 instead of 1970-1-1, the original timestamp also changed every 1/60 of a second instead of every 1 second.

In addition, Unix was invented in 1971 when computer systems were 32 bits, and if there were integers in 32, the maximum would be 2147483647(2^31-1).

So, to do a simple mathematical calculation, if using the timestamp calculation method at the time, the Unix timestamp can use 4294967296/ (60*60*24) /60 = 828.5 days (a day has 60*60*24 seconds, every 1/60 second will occupy a timestamp).

Imagine designing a computer system that only represents 828.5 days in time. But that was true of the original Unix.

Later, Unix developers realized that this was not sustainable and began to make changes.

At first, they changed the timestamp every 1/60 of a second to change the timestamp every second. This amplifies the time stamp by another 60 times. That’s 828.5*60/365 = 136 years.

At this point, on the one hand, 136 years is long enough, and a slight change in the epoch would not make much difference. On the other hand to facilitate memory and use.

So the epoch time was adjusted from 1971-01-01 to 1970-01-01.

As a result, the subsequent development languages have continued to use 1970-1-1.

So when we talk about time stamps, we usually refer to the total number of seconds in Greenwich Mean Time (GMT) from 00, 00 minutes, 00 seconds on January 01, 1970 to the present.

Epoch time and time zone

The epoch time Settings mentioned above are based on Greenwich Mean Time, or GMT time.

But each region of the world has its own time zone, which needs to be adjusted based on GMT time.

The display of 1970-01-01 08:00:00 is obviously affected by the time zone “How to explain to my Girlfriend why Japan is one hour ahead of China”, because China is in the 8th east zone, the time will be 8 hours ahead of standard time, which should be 1970-01-01 00:00:00.

A few years ago, a Reddit user named Vista980622 posted an article on Reddit that said, “If you change the date of the iPhone to January 1, 1970, the iPhone will become brick forever.”

Not long after the post was published, many people did not believe it and tried to set the date of the phone to January 1, 1970, only to find the phone turned off and turned on again.

Since we are in the eighth district east, the time is eight hours ahead of standard time. If we adjust the time to 1970-01-01 00:00:00, standard time will be eight hours short of this time, which is 16:0:00 on December 31, 1969.

However, for IOS devices, the time limit is 0 in UTC (GMT time) on January 1, 1970. When the user sets the time limit to 16:0 on December 31, 1969, the system will have a negative time.

Apple devices running IOS 8.0 to IOS 9.3 beta3 with a 64-bit processor (a7-A9X) will trigger this Bug, resulting in brick!





References:


http://en.wikipedia.org/wiki/Unix_time#History

http://mobile.zol.com.cn/569/5691666_all.html