发布此帖子之前,我已经在stackoverflow中提到了问题。就我而言,我需要将1426023505154转换为日期格式。为确保时间戳有效,我在http://www.epochconverter.com中进行了检查。我用这些代码进行转换。但这不起作用:
date_default_timezone_set('Asia/Calcutta');
$date = new DateTime();
$date->setTimestamp(1426023505154);
echo $date->format('U = Y-m-d H:i:s') ;
echo gmdate("Y-m-d\TH:i:s\Z", 1426023505154);
echo echo date('d-m-Y', 1426023505154);
但是所有结果都是错误的,例如:
47158-11-20 21:49:14
20-11-47158
请让我知道如何解决此问题。谢谢
问题是您的时间戳以毫秒为单位,$date->setTimestamp
使用秒,您可以通过除以1000来解决此问题
$date = new DateTime();
$value = 1426023505154;
$date->setTimestamp($value/1000);
尝试-->
echo date('Y-m-d H:i:s', 1426023505154 / 1000 );
// dividing by 1000 because the timestamp is in microseconds