Home >Backend Development >PHP Tutorial >php generate millisecond timestamp

php generate millisecond timestamp

巴扎黑
巴扎黑Original
2017-09-26 09:48:573875browse

The following editor will bring you an example of how to generate millisecond timestamps in PHP. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.

The php time function time() generates the seconds of the current time, but in some cases we need to obtain the current server time and GMT (Greenwich Mean Time) January 1970 The number of milliseconds at 0:00:00 is the same as the currentTimeMilis() function in Java.

Example:


public function getCurrentMilis() {

    $mill_time = microtime();
    $timeInfo = explode(' ', $mill_time);
    $milis_time = sprintf('%d%03d',$timeInfo[1],$timeInfo[0] * 1000);

    return $time;

  }

The above is the detailed content of php generate millisecond timestamp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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