Home  >  Article  >  Backend Development  >  How to convert time in milliseconds in php

How to convert time in milliseconds in php

藏色散人
藏色散人Original
2021-06-10 09:48:554069browse

How to convert milliseconds to time in php: First create a PHP sample file; then use the substr function to intercept the first ten digits of the millisecond timestamp; and finally convert the time through the date method.

How to convert time in milliseconds in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

Specific questions:

php How to convert milliseconds into time? PHP gets the specific Y-m-d H:i:s time through the millisecond timestamp?

php gets the specific Y-m-d H:i:s time through the millisecond timestamp?

For example, the millisecond timestamp is: The corresponding format of 1492396179000 is: 2017-04-17 10:29:39

Implementation method:

Use substr to intercept the first ten digits of the millisecond timestamp. Ah, for example:

date_default_timezone_set('PRC');
$time = 1492396179000;
$time = substr($time,0,10);
$date = date('Y-m-d H:i:s',$time);
echo $date;

[Recommended learning: PHP video tutorial]

The above is the detailed content of How to convert time in milliseconds in php. 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