time.strptime

Alex Martelli aleaxit at yahoo.com
Tue Sep 14 07:43:45 EDT 2004


Michele Simionato <michele.simionato at gmail.com> wrote:

> I have strings representing UTC dates and I want to convert them in time
> tuples using time.strptime. I have an issue with daylight savings. For
> instance
> 
> Tue Sep 14 06:06:15 2004
> 
> is converted to
> 
> (2004, 9, 14, 6, 6, 15, 1, 258, -1)
> 
> The last "-1" means daylight savings. I want it to be 0.
> I tried to play with time.daylight and time.timezone but with no luck.

>>> s='Tue Sep 14 06:06:15 2004'
>>> time.strptime(s)
(2004, 9, 14, 6, 6, 15, 1, 258, -1)
>>> time.strptime(s, '%a %b %d %H:%M:%S %Y')
(2004, 9, 14, 6, 6, 15, 1, 258, -1)
>>> time.strptime(s+' UTC', '%a %b %d %H:%M:%S %Y %Z')
(2004, 9, 14, 6, 6, 15, 1, 258, 0)


Alex



More information about the Python-list mailing list