I need to convert a windows hex 64 bit (big endian) date time to something readable in python?
example '01cb17701e9c885a'
converts to "Tue, 29 June 2010 09:47:42 UTC"
Any help would be appreciated.
Looks like a Win32 FILETIME value, which:
Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
To convert, convert the hexadecimal value to microseconds, then add that time delta to the base time value (also called the epoch):
import datetime as dt
filetime = '01cb17701e9c885a'
epoch = dt.datetime(1601, 1, 1, tzinfo=dt.UTC) # Jan 1, 1601 UTC
us = int(filetime, base=16) / 10 # 100ns intervals converted to microseconds
result = epoch + dt.timedelta(microseconds=us)
print(f'{result:%a, %d %B %Y %H:%M:%S %Z}') # formatted per question example
Output:
Tue, 29 June 2010 09:47:42 UTC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With