Search code examples
portable-executable

How to convert a hex TimeDateStamp DWORD value into human readable format?


Can anyone explain how to convert a Hex TimeDateStamp DWORD value into human readable format?

I'm just curious as to how a value such as 0x62444DB4 is converted into "Wednesday, 30 March 2022 10:31:48 PM"

I tried googling of course and could not find any explanation. But there are online converters available.

But I'm just interested in converting these values for myself.


Solution

  • Your value is a 32-bit Timestamp.

    Your datetime value is a 32-bit Unix Timestamp: The number of seconds since 1/1/1970.
    See https://unixtime.org/

    In most programming languages you can work with the hexadecimal notation directly.
    Implementation should not be done by one person alone, since a lot of engineering goes into it. Leap years, even leap seconds, timezones, daylight savings time, UTC... all these things need to be addressed when working with a timestamp.
    I have added my rough calculation below as a demonstration. Definitely use an existing package or library to work with timestamps.

    See the JavaScript code below for demonstration.
    There I multiply your value by 1000 because JavaScript works in Milliseconds. But otherwise this applies the same to other systems.

    let timestamp = 0x62444DB4;
    let dateTime = new Date(timestamp * 1000);
    console.log('Timestamp in seconds:', timestamp);
    console.log('Human-Readable:', dateTime.toDateString() + ' ' + dateTime.toTimeString());
    
    // Rough output, just for the time.
    // Year month and day get really messy with timezones, leap years, etc.
    let hours = Math.floor(timestamp/3600) % 24;
    let minutes = Math.floor(timestamp/60) % 60;
    let seconds = Math.floor(timestamp) % 60;
    console.log('Using our own time calculation:', hours + ':' + minutes + ':' + seconds);