How does php get the specific Y-m-d H:i:s time through millisecond timestamp?
PHPz
PHPz 2017-05-16 13:12:50
0
2
538

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

PHPz
PHPz

学习是最好的投资!

reply all(2)
左手右手慢动作

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);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template