Home > Web Front-end > JS Tutorial > Detailed explanation of the function of Javascript new Date().valueOf() and the origin of timestamp_Basic knowledge

Detailed explanation of the function of Javascript new Date().valueOf() and the origin of timestamp_Basic knowledge

WBOY
Release: 2016-05-16 17:35:33
Original
1350 people have browsed it

As we all know, time type data in PHP can be directly converted into timestamps. In front-end script js, there is also a way to achieve this, which is valueOf()

For example, we can use this code to output the timestamp of the current time point

Copy code The code is as follows:



So what is a timestamp?

The timestamp is all the seconds from 0:00:00 on January 1, 1970 to the current time point. 1970.1.1 0:0:0 This time is the so-called "time epoch" in IT. I believe you have seen it in many articles. For example, Oracle time display, time calculation in Unix and Linux systems, etc. Then why choose 1970 instead of 1900? Let us explain its origin next.

1. When 32-bit computers just started to emerge,
The maximum value that the so-called integer type data can represent is:
System.out.println(Integer.MAX_VALUE);
2147483647
2. The total number of seconds of 365 in a year is 31536000,
3. Divide the two, 2147483647/31536000=68.1,
4. In other words, in the context of 32 bits, the maximum value that can be expressed The long-term interval is 68 years
5. If you count from 1970, it can be said that the maximum time will be reached at 03:14:07 on January 19, 2038,
6. After this time point, The time of all 32-bit operating systems will become 10000000 00000000 00000000 00000000
which is 20:45:52 on December 13, 1901. This will cause time regression, and some software may have major abnormalities.

To summarize the above points, the people who came up with this set of things were actually those who were playing with UNIX at the earliest. They considered that 68 years is not that long, so they started counting these 68 years from 1970. Their hopes Yes, during these 68 years, those who came later could come up with a better mechanism as soon as possible to change this restriction. . . Sure enough, the rise of 64-bit has changed this "end of time" from
January 19, 2038, 03:14:07 - " 292,277,026,596 December 4, 15:30:08
So, this If the number is big enough, the "end of the world" of computer time will really be the end of the world
Code changes the world, my "Source Code", my world!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template