PHP: convert C# 64-bit timestamp to Unix Timestamp
<p>I am copying a C# function to PHP. In C#, a GUID, DateTime and boolean are converted to bytes. Next, the byte arrays get merged and encoded. The last step is to convert this to base64.</p>

<p>The array of bytes exists of the following parts:</p>

<pre><code>GUID: 16 bytes
Timestamp: 8 bytes
Boolean: 1 byte
</code></pre>

<p>In php, I already converted the base64 and decoded the string back to bytes. I also managed to convert the first 16 bytes to the GUID. I validated the bytes PHP returned me and they are correct.</p>

<p>Now I am converting the 8 bytes to a timestamp in PHP. So far I have no luck. I guess the problem is the fact that it returns an int64.</p>

<p><strong>C#</strong></p>

<p>This is the C# byte array to datetime convert:</p>

<pre><code>public DateTime Timestamp;
......
byte[] timestamp_bytes = new byte[8];
input.Read(timestamp_bytes, 0, 8);
Timestamp = DateTime.FromBinary(System.BitConverter.ToInt64(timestamp_bytes, 0));
</code></pre>

<p>And this is the C# datetime to byte array convert:</p>

<pre><code>public DateTime Timestamp;
......
byte[] timestamp_bytes = System.BitConverter.GetBytes(Timestamp.ToBinary());
</code></pre>

<p>When I output Timestamp.ToString(), i 'll get <em>23-12-2011 09:54:56</em> in both cases.</p>

<p><strong>PHP</strong></p>

<p>In PHP I managed to get the hex of the 8 bytes:</p>

<pre><code>$bin = pack("C*", 119, 23, 124, 173, 103, 143, 206, 136);
$hex = unpack("H*", $bin);
</code></pre>

<p>What should I do next? I tried already some methods to convert, but I never seem to get the right answer.</p>

<p><strong>Additional info:</strong></p>

<p>The 8 bytes are: 119, 23, 124, 173, 103, 143, 206, 136</p>

<p>The hexstring is: 77177cad678fce88</p>

<p>The datetime I should get: 23-12-2011 09:54:56</p>

<p>php -r 'echo PHP_INT_MAX;' returns 9223372036854775807</p>

<p>The C# app is not under my authority, so I cannot guarantee I can alter it</p>
