Datetime with float seconds

Gabriel Genellina gagsl-py2 at
Thu Aug 6 02:54:07 CEST 2009

En Wed, 05 Aug 2009 09:50:04 -0300, kpal <kpalamartchouk at>

> The standard datetime has 1 microsecond granularity.

Note that this is the finest granularity a datetime object can store, NOT
the precision of by example.

> My application
> needs finer time resolution, preferably float seconds.

"float seconds" doesn't mean much. time.time returns float seconds, but
its precision is around 15ms on Windows.

> Is there an
> alternative to the out-of-the-box datetime? Timezone support is not
> essential.

On Windows, use time.clock(), which internally uses
QueryPerformanceCounter. The resolution depends on your hardware, but it's
typically better than 1 microsecond. If you want to know the actual value:

py> from ctypes import *
py> kernel32=windll.kernel32
py> QueryPerformanceCounter=kernel32.QueryPerformanceCounter
py> QueryPerformanceFrequency=kernel32.QueryPerformanceFrequency
py> plonglong = POINTER(c_longlong)
py> QueryPerformanceFrequency.argtypes = [plonglong]
py> freq = c_longlong()
py> QueryPerformanceFrequency(byref(freq))
py> freq

That is, on my system the resolution is 1/3579545s, or better than 300ns

Gabriel Genellina

More information about the Python-list mailing list