This format that you put in the question saves the time in the last five hexadecimal digits, and the rest is the date (both with an adjustment factor).
You can do a conversion from NFA to timestamp with this formula:
function nfaToTs($nfa) {
$nfadata = hexdec(substr($nfa,0,-5));
$nfahora = hexdec(substr($nfa,-5));
return ($nfadata-25569) * 86400 + ($nfahora - 7) / 11.574;
}
How to use:
$timestamp = nfaToTs('A70171480');
// Formate como quiser depois:
echo gmdate('Y-m-d H:i:s', $timestamp);
See working at IDEONE .
From timestamp to NFA, it is a simple inversion of logic:
function tsToNfa($ts) {
$hexdata = substr('0000' .dechex($ts / 86400 + 25569 ), -4);
$hexhora = substr('00000'.dechex($ts % 86400 * 11.574 + 7), -5);
return $hexdata.$hexhora;
}
How to use:
// qualquer coisa que retorne um timestamp
$ts = strtotime('1980-01-31 15:53:09 GMT');
echo tsToNfa($ts);
See working at IDEONE .
Curiosities:
-
The number of days between the posix timestamp and the first day of the year 1900 is 25567
, perhaps the 25569
has some relation to this 70-year setting;
-
In hex, the decimal 1.000.000
is 0xF4240
, which is the NFA time limit;
-
One day has 86400
seconds, and when we divide 1.000.000
by 86.400
result by chance is 11.574
;
Further Reading:
How do hex numbers work ?
link