HEX Date creation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim

    HEX Date creation

    Can someone tell me how the following date and time is created to the
    Hex value (also shown below)?

    Tuesday, July 08, 2003 10:56:38 AM

    hex:00,90,a6,7b ,66,45,c3,01

    I need to be able to create the hex value for any date, but am not
    sure how to break it down. Serail Parts?
  • FISH

    #2
    Re: HEX Date creation

    james.overland@ teldta.com (Jim) wrote in message news:<e5679de0. 0307081040.7a61 8e8d@posting.go ogle.com>...[color=blue]
    > Can someone tell me how the following date and time is created to the
    > Hex value (also shown below)?
    >
    > Tuesday, July 08, 2003 10:56:38 AM
    >
    > hex:00,90,a6,7b ,66,45,c3,01
    >
    > I need to be able to create the hex value for any date, but am not
    > sure how to break it down. Serail Parts?[/color]


    Timestamps can be expressed as seconds or milliseconds since a
    given epoch. If you check out java.util.Date you'll see it can
    'convert' dates to and from this type of format, using a 'long'.

    There are eight hex numbers above, each representing a byte.
    The first thing to try is to see if these bytes represent a
    long, by forming the digits into a String (minus the commas)
    and converting said string to a Date object by parsing the
    value using base 16.

    String hexString="0090 a67b6645c301"; // Woundn't be hardcoded!
    Date d = new Date(Long.parse Long(hexString, 16));

    Obviously this will only work if the value represented by the
    hex string is scaled the same as Java expects (ie: measures
    milliseconds, not seconds) and uses the same epoch. If not,
    you'll have to tinker with the long value to get it in the same
    scale, and/or adjust the epoch. (Java uses Jan 1st 1970 00:00:00
    GMT --- other languages/API's use 1900 not 1970!)


    -FISH- ><>

    Comment

    Working...