PHP millisecond timestamp calculation method, how to obtain millisecond timestamp in PHP

WBOY
Release: 2016-07-25 08:51:17
Original
2035 people have browsed it
An example of how to obtain millisecond timestamps in PHP. The time function in PHP programming can obtain timestamps. This article compares the different writing methods and efficiencies of how to obtain millisecond timestamps in PHP. For those who are interested, please refer to it.

php millisecond timestamp calculation method

The timestamp obtained by the time() function in php, the unit is seconds.

The timestamp obtained by the front-end js, the unit is milliseconds.

How to unify the timestamps of JS and PHP, that is, how to get the millisecond timestamp using PHP?

Example:

Copy code Code example: "; echo getMillisecond_new().' PHP millisecond-getMillisecond_new()'; /* * Idea: * 1. Use microtime() to obtain the microsecond timestamp, format: 0.69718900 1420440552 * 2. Add the two parts before and after × 1000, then round to round($float,0) * Seconds time()-->milliseconds-->microseconds microtime(), the interval between two is 1000 decimal * In this way, it can be consistent with the timestamp of the front-end JS * JS: new Date().getTime() gets the millisecond timestamp */ ?> time
<script> var time=new Date(); var mtime=time.getTime(); document.write(mtime+' JS获得毫秒时间戳'); </script>

Run results: 1424069168633 PHP milliseconds-getMillisecond() 1424069168633 PHP millisecond-getMillisecond_new() 1424069168643 JS gets millisecond timestamp It can be seen that the third timestamp value is slightly larger than the first two. This is the time consumed by the code running, which is normal.



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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!