Reputation: 169
I got the following timestamp long value from database 147836340000 and I want to convert it on data and time. I have tried to use the following:
$timestamp=147836340000;
print_r(date('m/d/Y H:i:s', $timestamp));
But unfortunately I am getting the following error:
date() expects parameter 2 to be integer, float given
Please advice on what I need to do.
Upvotes: 2
Views: 11388
Reputation: 3189
It's probably JS timestamp, so you need to divide it by 1000. But in your example, the date looks off by one extra 0
at the end. It should be 1478363400000
according to JS specs.
Your version:
$timestamp=147836340000;
print_r(date('m/d/Y H:i:s', $timestamp));
> 09/30/6654 18:00:00
Try this one (Online Demo):
$timestamp=(int) 147836340000 / 1000;
echo "Wrong: " . date('m/d/Y H:i:s', $timestamp) . PHP_EOL;
$timestamp=(int) 1478363400000 / 1000;
echo "Corrected: " . date('m/d/Y H:i:s', $timestamp) . PHP_EOL;
> Wrong: 09/08/1974 02:39:00
> Corrected: 11/05/2016 17:30:00
More details can be found here: Timestamp between Javascript and PHP
Upvotes: 5