2016-04-11 132 views
1

我想从一个来自api的时间戳得到日期,但它会显示错误的日期。从时间戳获取日期:错误的日期在php

<?php 
//its from the api also its timestamp of the today 
$timestamp="1460364355000"; 
// but it will shows the wrong date. 
echo date('Y/m/d',$timestamp); 

?> 

当我检查上述时间戳this website它会显示正确的日期,但使用PHP我会得到错误的日期。

回答

1

您需要将时间戳除以1000,这是从时间戳中删除毫秒。

<?php 
    $timestamp=1460364355000/1000; 
    echo date('Y/m/d',$timestamp); 
?> 
+0

是它解决了我的问题 –

+0

@BlessanKurien不客气:) – Panda

+0

需要等待6分钟接受答案 –