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

In Win32 often you'll find time stored in 100-nanosecond intervals since January 1, 1600 UTC. It is stored in a 64-bit value which uses 2 32 bit parts to store the time. The following is a function that returns the time in the typical format the python time libraries use (seconds since 1970).

Python, 19 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import time

def conv_time(l,h):
    #converts 64-bit integer specifying the number of 100-nanosecond
    #intervals which have passed since January 1, 1601.
    #This 64-bit value is split into the
    #two 32 bits  stored in the structure.
    d=116444736000000000L #difference between 1601 and 1970
    #we divide by 10million to convert to seconds
    return (((long(h)<< 32) + long(l))-d)/10000000    

For example, active directory in windows uses this time to note when a password was last set.

If you have a com object representing a user in active directory:
user='LDAP://cn=fred,OU=office1,DC=company,DC=com'
user_obj=win32com.client.GetObject(user)

To get the time the password was last set you would do the following:
print conv_time(user.pwdLastSet.lowpart,user.pwdLastSet.highpart) 

Microsoft's method of storing time will let them record dates for thousands of years. Unfortunately, it is not a method python libraries are familiar with.

You can use this function with things as diverse as times in active directory and dates found in cookies created by Microsoft's Internet Explorer.

Created by John Nielsen on Fri, 3 Sep 2004 (PSF)
Python recipes (4591)
John Nielsen's recipes (36)

Required Modules

  • (none specified)

Other Information and Tasks