Php function to convert from 64bit ntp timestamp

iirc, the most significant 32 bits are the number of seconds in unix time, and the lower 32 bits are the fractions of a second - 2^32-1 being almost 1 second.

I use BC math functions here because I don't believe that integer math of more than 32 bit precision is guarenteed in PHP :

Code:
$t = "5063470863794978160";

$n_32 = bcpow(2, 32);
$unix_time = bcdiv($t, $n_32);
$fraction = bcmod($t, $n_32);

printf("NTP time : %u:%u\n", $unix_time, $fraction);
echo "       = : " . strftime("%c", $unix_time) . "\n";
 
Back
Top Bottom