LastTradedTimeStamp 44-48 Bytes Conversion

Shabeershah2002
Can anyone help me to understand why i am not able to convert timestamp bytes to proper TimeStamp ?
I am using C# , all other fields successfully converted but timestamp is not properly converted

see below packets which is 44-48 from the quote pack , and the converted value shows 1531211662 !!


each 4 bytes have reversed and prices market depth all are getting properly using BitConverter.ToInt32(PacketFields, 0)


I have tried DateTime.FromBinary(BitConverter.ToInt32(PacketFields, 0)) this way aswell and the output is #1/1/0001 12:02:33 AM#


please help
Tagged:
  • HowUTrade
    @Shabeershah2002

    All the packets when cast returns number data type (Int16 or Int32)
    LastTradedTimeStamp is Unix Time not DateTime.
    So DateTime.FromBinary will not work.

    Yo need to do;
    1. Get the Int32 (Unix time) from the packets BitConverter.ToInt32(PacketFields, 0)
    2. Convert the Unix timestamp to DateTime.

    public static DateTime UnixTimeStampToDateTime( double unixTimeStamp )
    {
    // Unix timestamp is seconds past epoch
    System.DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc);
    dtDateTime = dtDateTime.AddSeconds( unixTimeStamp ).ToLocalTime();
    return dtDateTime;
    }
    Your example '1531211662' converts to Tuesday, July 10, 2018 2:04:22 PM
  • Shabeershah2002
    Super !, thank you so much
    it works great ......... <3
This discussion has been closed.