time: Daylight savings confusion
google at mrabarnett.plus.com
Thu Feb 5 16:29:20 CET 2009
Matt Nordhoff wrote:
> 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?
>> 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  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 ;-).
Windows does apply the current value of DST when converting from UTC to
The problem is that the rules for when DST starts and ends might change
over time and from place to place, and local time depends on the
Probably the best you can do is just to apply the current rules and
accept that the result might not match what the local time actually was.
More information about the Python-list