How to convert HEX data to Datetime

后端 未结 2 1521
抹茶落季
抹茶落季 2021-01-24 21:42

I have a hex string like this 529CD17C.This is corresponding to One date time 12/2/2013 06:29:16 PM .(ie in MM/dd/yyyy hh:mm:ss AM/PM).How can i do this in c# coding

相关标签:
2条回答
  • 2021-01-24 22:12

    You are working with a UNIX time stamp. First you need to convert it to an integer value, then go ahead and add that amount of seconds to the epoch (January 1, 1970).

    Here is an example:

    string hexValue = "529CD17C";
    int secondsAfterEpoch = Int32.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
    DateTime epoch = new DateTime(1970, 1, 1);
    DateTime myDateTime = epoch.AddSeconds(secondsAfterEpoch);
    Console.WriteLine(myDateTime);
    

    Hope that was helpful!

    0 讨论(0)
  • 2021-01-24 22:30

    Here is someone with the same question http://social.msdn.microsoft.com/Forums/en-US/c9624a19-1ef6-4f60-b063-527beb36de1d/hex-string-to-datetime-conversion It looks like the function provided could work.

    They first convert the HEX value to an integer and then convert the integer to a date type.

    0 讨论(0)
提交回复
热议问题