Binary to Date (C #) 64-bit format

We have a binary from which we have determined the following dates (as Int64). We now have the following facts about the Date / Time format;

  • 64 bit date has microsecond resolution
  • A 64-bit date has a range of 4095 years.
  • Int64 9053167636875050944 (0x7DA34FFFFFFFFFC0) = March 9, 2010
  • Int64 9053176432968073152 (0x7DA357FFFFFFFFC0) = March 10, 2010
  • Int64 9053185229061095360 (0x7DA35FFFFFFFFFC0) = March 11, 2010
  • Int64 9053194025154117568 (0x7DA367FFFFFFFFC0) = March 12, 2010

Any help figuring out a way to convert this value to a valid C # date / time is appreciated.

+2


a source to share


5 answers


Here's the solution:

string hex_data = "7DA34FFFFFFFFFC0";
        Int64 int_datetime = Convert.ToInt64(hex_data, 16);

        int year = (int)(int_datetime >> 52);
        int month = (int)((int_datetime >> 48) & 0x0F);
        int day = (int)(((int_datetime >> 43) & 0x1F));

        int hour = (int)(((int_datetime >> 38) & 0x1F)) > 24 ? 0 : (int)(((int_datetime >> 38) & 0x1F));
        int min = (int)(((int_datetime >> 32) & 0x3F)) > 60 ? 0 : (int)(((int_datetime >> 32) & 0x3F));
        int sec = (int)(((int_datetime >> 26) & 0x3F)) > 60 ? 0 : (int)(((int_datetime >> 26) & 0x3F));
        int mili_sec = (int)(((int_datetime >> 16) & 0x3FF)) > 100 ? 0 : (int)(((int_datetime >> 16) & 0x3FF));
        int micro_sec = (int)(((int_datetime >> 6) & 0x3FF)) > 100 ? 0 : (int)(((int_datetime >> 6) & 0x3FF));

        string str_date_time = year.ToString("D4") + "/" + month.ToString("D2") + "/" + day.ToString("D2") + " " + hour.ToString("D2") + ":" + min.ToString("D2") + ":" 
            + sec.ToString("D2") + "." + mili_sec.ToString("D3");

        DateTime date_time_dt=DateTime.Parse(str_date_time);

      

Return:



09/03/2010 12:00:00 AM

      

in the date_time_dt object. I don't think the DateTime object supports microseconds in C #, but I could be wrong.

0


a source


From the hexadecimal data, at least it's clear:

0x7da = 2010



The next May 3, most likely March (month 3).

+2


a source


0x7da = 2010
0x3 = 3 (March)
01001111 = the first 5 bits appear to be day (9), the last three are always 1 of what you showed us
The rest of the bits are probably additional resolution (hours, minutes, etc. .).

+2


a source


Disconnecting from what @BlueRaja Green Unic said, here's how you parsed it:

        var X = 0x7da34fffffffffc0L;
        var Year = X >> 52;
        var Month = (X >> 48) & 0xf;
        var Day = (X >> 43) & 0x1f;

      

+2


a source


To clarify. These are not standard C # datetime ticks of dateData. For anyone wanting to know how dateTime is masked in C # see here: https://referencesource.microsoft.com/#mscorlib/system/datetime.cs,f6ea9c9a0d4b5e43

0


a source







All Articles