php gets the specific Y-m-d H:i:s time through millisecond timestamp?
For example, the millisecond timestamp is: 1492396179000 and the corresponding format is: 2017-04-17 10:29:39
1492396179000
2017-04-17 10:29:39
学习是最好的投资!
Just use substr to intercept the first ten digits of the millisecond timestamp. 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;
date_default_timezone_set('PRC'); $mtimestamp = sprintf("%.3f", microtime(true)); // 带毫秒的时间戳 $timestamp = floor($mtimestamp); // 时间戳 $milliseconds = round(($mtimestamp - $timestamp) * 1000); // 毫秒 $datetime = date("Y-m-d H:i:s", $timestamp) . '.' . $milliseconds; echo sprintf("%s -> %s", $mtimestamp, $datetime);
Just use substr to intercept the first ten digits of the millisecond timestamp. For example: