I’m trying to convert a timestamp string to Date in PHP. I have following code
date_default_timezone_set('Asia/Calcutta');
$time = (int)$_POST['timestamp'];
$timeString = date('H:i:s',$time);
Howevever, I always get timeString as 08:44:07 no matter what. I figured that timestamp is greater than what 32 bit integer could store, probably that’s why this conversion always gives a default maximum value for integers.
How can I create a 64-bit integer in PHP? I have a 64-bit machine and 64-bit Windows 7 running on it.
Is there a better way to convert timestamp string to local time?
EDIT:
timestamp as a string is being sent by javascript – “1330582437883”
My completely baseless stab into the dark:
The timestamp value is coming from Javascript. Javascript measures timestamps in milliseconds, not seconds like PHP. So the value is 1000 times greater than what PHP expects. Divide the value by 1000 before sending it to PHP. Alternatively do that server side, for which you’ll probably have to use
bcdivto get a precise value.