Search code examples
phptimestampunix-timestamp

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


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?


Solution

  • 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