How to convert a 13 digit Unix Timestamp to Date and time?

glendon philipp Baculio picture glendon philipp Baculio · Oct 3, 2015 · Viewed 47.8k times · Source

I have this 13 digit timestamp 1443852054000 that i want to convert to date and time but dont succeed. I have tried this codes:

echo date('Y-m-d h:i:s',$item->timestamp); 

doesnt work for me and also this

$unix_time = date('Ymdhis', strtotime($datetime ));

and this :

$item = strtotime($txn_row['appoint_date']); 
<?php echo date("Y-m-d H:i:s", $time); ?>

what should i use?

Answer

u_mulder picture u_mulder · Oct 3, 2015

This timestamp is in milliseconds, not in seconds. Divide it by 1000 and use date function:

echo date('Y-m-d h:i:s', $item->timestamp / 1000);
// e.g
echo date('Y-m-d h:i:s',1443852054000/1000);
// shows 2015-10-03 02:00:54