Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert 64 bit windows date time in python

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.

like image 479
Dave Nardoni Avatar asked Jul 03 '26 18:07

Dave Nardoni


1 Answers

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
like image 183
Mark Tolonen Avatar answered Jul 06 '26 06:07

Mark Tolonen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!