time: Daylight savings confusion

Matt Nordhoff mnordhoff at mattnordhoff.com
Thu Feb 5 10:39:47 CET 2009

Tim H wrote:
> On Win XP 64bit, Python 2.6.1 64bit
> I am trying to rename files by their creation time.
> It seems the time module is too smart for its own good here.
> time.localtime(os.path.getctime(f)) returns a value one hour off from
> what windows reports for files that were created when Daylight savings
> time was in effect (ie when the tm_isdst field is one).  I can kludge
> it, but am I missing the "right" way to do it?
> Tim
> full code:

<snip full code>

>From what I remember, this is a bug in the Win32 API. Python probably
could hack around it, but, well, I guess it doesn't.

Googling a bit, Perl's Win32::UTCFileTime module [1] provides
workarounds (not for Python, of course, but it could probably be ported)
and explains all the gory details (which I have not read, so maybe I
misunderstand ;-).


More information about the Python-list mailing list