Ferryboi
Ferryboi

Reputation: 119

How to display time stamp correctly

The api we use generates a set of time stamps for us - We have tried to turn these into the proper values but no matter what we try it is just coming back as around 24-04-1937, 10:53:52 which would be good .. except it was only generated around 5 days ago

The time stamps we have to work off are in the format : 1.321818372E+12

The API developer had posted this section to help someone else with the same issue but for some reason it doesnt seem to be working for us we have tried to change a few variables on the test server but the date just keeps going further back in time

$achname = $achievements[0]['name'];
$achtime = substr($achievements[0]['timestamp'], 0, -3);
$format = '%d-%m-%Y, %H:%M:%S';
$strf = strftime($format, $achtime);

Im just not too sure as to what is wrong with it

Thanks

Upvotes: 1

Views: 152

Answers (1)

JohnP
JohnP

Reputation: 50019

What you're looking at is a JS timestamp, it's in milliseconds. Just divide it by 1000 to get the UNIX timestamp.

$timestamp = $achievements[0]['timestamp'] / 1000;
echo date('d-m-Y', $timestamp);

Upvotes: 4

Related Questions