php method to get the current millisecond timestamp: use the [microtime()] function to get it, the code is [list($msec, $sec) = explode(' ', microtime());].
php method to get the current millisecond timestamp:
provides a microtime() function. If called Without optional parameters, this function returns a string in the format "msec sec", where sec is the number of seconds since the Unix epoch (0:00:00 January 1, 1970 GMT) and msec is the microsecond portion . Both parts of the string are returned in seconds.
Detailed description of microtime() function
<?php echo microtime(); //输出结果是 //0.25139300 1138197510
Note that its result is divided into two parts, that is, the first half is milliseconds (but the unit is seconds) , the second half is seconds.
Now, we make modifications based on this, as follows:
<?php list($msec, $sec) = explode(' ', microtime()); $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
That’s it, $msectime is the current number of milliseconds! These two lines can be encapsulated into a function for easy use.
<?php //返回当前的毫秒时间戳 function msectime() { list($msec, $sec) = explode(' ', microtime()); $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); return $msectime; }
Note: sprintf('%.0f', $num) outputs a floating point number without a decimal part
The thing is not over yet. After I changed the timestamp to millisecond level, When the database data was updated again, it was prompted that it was out of range. It turned out that I used int type to store the second-level timestamp obtained by the time() function in the database. The storage range was sufficient. If I changed it to millisecond level, I had to change it. It is of BIGINT type.
integer type byte range (with symbols) range (non-symbol) use
Tinyint 1 byte (-128, 127) (0,255) small integer Value
SMALLINT 2 bytes ( 65 535) ’ to 3 byte through ’’’’ out's ’ ’ s ’ through ’ through through ’’'' through'''' through through‐‐to‐to‐‐‐under‐ coming to 3 bytes to be 88 608, 8 388 607) (0 , 16 777 215) Large integer value
INT or INTEGER 4 bytes (-2 147 483 648, 2 147 483 647) (0, 4 294 967 295) Large integer value
BIGINT 8 bytes (-9 233 372 036 854 775 808, 9 223 372 036 854 775 807) (0, 18 446 744 073 709 551 615) Very large integer value
Want to know more about programming To learn, please pay attention to thephp training
The above is the detailed content of How to get the current millisecond timestamp in php. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


Hot AI Tools

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

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

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft