How to convert HEX data to Datetime

后端 未结 2 1522
抹茶落季
抹茶落季 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!

提交回复
热议问题