Welcome, guest | Sign In | My Account | Store | Cart

Converting a FILTIME in a datetime is sometime verry useful if you use ctypes with win API.

Python, 8 lines
1
2
3
4
5
6
7
8
import datetime

_FILETIME_null_date = datetime.datetime(1601, 1, 1, 0, 0, 0)
def FiletimeToDateTime(ft):
    timestamp = ft.dwHighDateTime
    timestamp <<= 32
    timestamp |= ft.dwLowDateTime
    return _FILETIME_null_date + datetime.timedelta(microseconds=timestamp/10)

1 comment

Kent Tenney 17 years ago  # | flag

type problem. This looks interesting, but I'm missing something::

>>> import os
>>> statinfo = os.stat('/tmp/test.file')
>>> print type(statinfo.st_ctime)



>>> cdt = FiletimeToDateTime(ctypes.c_long(creation))

TypeError: int expected instead of float instance

What am I doing wrong?

Thanks, Kent

Created by Julian Rath on Tue, 27 Mar 2007 (PSF)
Python recipes (4591)
Julian Rath's recipes (1)

Required Modules

Other Information and Tasks