Conversion of hex value in milliseconds to datetime in c#2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nmsreddi
    Contributor
    • Jul 2006
    • 366

    Conversion of hex value in milliseconds to datetime in c#2005

    Hi friends

    I am doing a project related embeded systems ,where my application reads data that generated by the device that connected to my application ,

    the protocol that used for developing the firm ware of the device is DNP3

    the date,month,year ,hh,min,sec that generated by the device is in hexadecimal format

    ex:EC5461887011 (the value generated by device in milli seconds from 1970 )

    now my application should convert the above format to the datetime format in c#

    can any one there for any idea or any existing function related to this


    Regards

    Msreddy
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Do you get a series of bytes (like a byte[]) or do you get a text string of "ECCEE4554" ?

    Comment

    • balabaster
      Recognized Expert Contributor
      • Mar 2007
      • 798

      #3
      Originally posted by Plater
      Do you get a series of bytes (like a byte[]) or do you get a text string of "ECCEE4554" ?
      Now - "since 1970" is a fairly broad term...so you need to figure out the exact time to run from...so assuming we can figure this out:

      Convert the hex to decimal...or not (if not, just add the hex notification so that the compiler knows how to convert it).

      What about this? I'm assuming by "1970" you meant since 1/1/1970 12:00:00 AM otherwise just change the start date accordingly. Use the &H (VB) or 0x (C#) flag to notify the compiler that this value is hexadecimal. Obviously you would replace the literal that I used in my demo with a variable containing the literal value.
      VB
      Code:
      Dim StartDate As DateTime = Convert.ToDateTime("1/1/1970 12:00:00 AM")
      Dim OutputDate As DateTime = StartDate.AddMilliseconds(&HECCEE4554)
      C#
      Code:
      System.DateTime StartDate = Convert.ToDateTime("1/1/1970 12:00:00 AM");
      DateTime OutputDate = StartDate.AddMilliseconds(&HECCEE4554);
      Hmm...just tested that with the original Hex string (&hEC5461887011 ) and it crashes because the number is too large...are we sure this isn't a byte array? Or in some other measure than milliseconds? If I add ticks, but I don't suppose that is correct...the resulting date doesn't seem high enough.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        I am pretty sure that's just a made up hex number, as it's only 6bytes (whoever heard of a 24bit integer...)

        Comment

        Working...