For web developers, timestamps are a very important tool. In PHP, we can get the timestamp of the current time through the built-in time() function. A timestamp is an integer representing the number of seconds between the current time and the beginning of the Unix epoch (January 1, 1970).
So, how many digits does the PHP timestamp have? The answer is: PHP timestamps are usually 10 digits. However, there is another case where it is 13 bits (millisecond timestamp). Let’s take a look at it below.
- 10-digit timestamp
Normally, PHP's timestamp is 10 digits, representing the number of seconds since the Unix epoch. The current timestamp can be obtained through the time() function:
echo time(); //输出当前时间戳
The timestamp obtained through this function is an integer, for example: 1624278852. This number represents the number of seconds that have elapsed since the Unix epoch to the current time (June 21, 2021 18:47:32).
Simply put, this number represents the number of seconds from the beginning of the Unix epoch to the current time.
- 13-digit timestamp
In some high-performance computer systems, if 10-digit timestamps are used, duplicate timestamps will occur. question. At this time, we need to use a 13-digit timestamp.
Different from the 10-digit timestamp, the 13-digit timestamp represents the number of milliseconds from the beginning of the Unix epoch to the present. In PHP, we can get the 13-digit timestamp through the following method:
echo round(microtime(true) * 1000);
Note that the microtime(true) function is used here, which returns the current number of microseconds (six digits after the decimal point), and then The result is multiplied by 1000 to get the milliseconds of the current time, and finally rounded to get a 13-digit timestamp.
In some situations where high-precision timestamps are required, we can use 13-digit timestamps to ensure the uniqueness of the timestamp.
Summary
In PHP, timestamp is a very important concept, through which time can be compared and calculated. Typically, PHP timestamps are 10 digits representing the number of seconds since the Unix epoch. But in some high-precision situations, we need to use a 13-digit timestamp to represent the number of milliseconds from the beginning of the Unix epoch to the present.
The above is the detailed content of How many digits are timestamps in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment






