2016-04-11 133 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分鐘接受答案 –