Byte Array in string format back to datetime

Viewed 502

I need to interact with a service which is returning me a string.... however this is a representation of a Byte Array in text.

Then I need convert this string to a byte array and after convert it to DateTime....

To make things worse, I really do not know what type of encoding is been used.....the only few things I know are 2 samples that were provided to me:

  • Exact received string: "32,6,23,8,69,80,48,36" needs to give me the datetime: 17.6.2020 08:45:50
  • Exact received string: "32,6,23,8,69,87,118,148" needs to give me the datetime: 17.6.2020 17:45:57

Any idea on how to do this, or at least some points that could help me move on into a solution? Thanks.

#Update1:

I have tried the following code but the results are not what I am looking for:

byte[] bytes = { 32, 6, 23, 8, 69, 80, 48, 36 };
long longVar = BitConverter.ToInt64(bytes, 0);
DateTime dateTimeVar = new DateTime(longVar);  // Result: 5/21/8264 9:36:06 AM

string t1 = Encoding.UTF8.GetString(bytes); //  " \u0006\u0017\bEP0$"
string t2 = Encoding.ASCII.GetString(bytes); // " \u0006\u0017\bEP0$"
string t3 = Encoding.BigEndianUnicode.GetString(bytes); // " ᜈ䕐〤"
string t4 = Encoding.UTF32.GetString(bytes); // "��"
string t5 = Encoding.UTF7.GetString(bytes); // " \u0006\u0017\bEP0$"
string t6 = Convert.ToBase64String(bytes);  // IAYXCEVQMCQ=

long longVar = BitConverter.ToInt64({ 32, 6, 23, 8, 69, 87, 118, 148 }, 0); 
// This one even gives me a negative number: -7748910154844273120

#Update2:

I know that the dates are obtained from an OPC server and other systems in between.... what is happening till the data arrives in my service I really have no idea.... Meanwhile I google for OPC and datetime and got the following link about datetimes, maybe I get some clarification.

0 Answers
Related