Created
April 4, 2013 18:56
-
-
Save williballenthin/5313118 to your computer and use it in GitHub Desktop.
Parse a hex encoded Windows timestamp into a readable ISO formatted timestamp.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_windows_timestamp(hex_str): | |
""" | |
@type hex_str: str | |
@param hex_str: A string that contains a hex encoded QWORD (8 bytes) that are a Windows timestamp. | |
@rtype: str | |
@return: A string that contains an ISO formatted timestamp. | |
""" | |
import struct, binascii | |
from datetime import datetime | |
return datetime.utcfromtimestamp(float(struct.unpack_from("<Q", binascii.unhexlify(hex_str.replace(" ", "")))[0]) * 1e-7 - 11644473600).isoformat("T") | |
if __name__ == "__main__": | |
import sys | |
print(parse_windows_timestamp(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: