tags:

views:

503

answers:

2

I know how to do this the other way around... it would be:

>>> dt.rfc822()
'Sun, 09 Mar 1997 13:45:00 -0500'
+6  A: 

In [1]: import rfc822     # This only works for python 2 series

In [2]: rfc822.parsedate_tz('Sun, 09 Mar 1997 13:45:00 -0500')
Out[2]: (1997, 3, 9, 13, 45, 0, 0, 1, 0, -18000)

in python3 parsedate_tz has moved to email.utils


>>> import email.utils   # this works on Python2.5 and up
>>> email.utils.parsedate_tz('Sun, 09 Mar 1997 13:45:00 -0500')
(1997, 3, 9, 13, 45, 0, 0, 1, -1, -18000)
gnibbler
I thought rf822 was deprecated?
Udbhav
Thanks, fixed it. There is no deprecation warning even in 2.6 :(
gnibbler
A: 

If you strip off the time zone, you can do it like this:

datetime.datetime.strptime('Sun, 09 Mar 1997 13:45:00', '%a, %d %b %Y %H:%M:%S')
Daniel Roseman
This won't work for most locale settings.
Denis Otkidach