Parse date/time from a string
Question: I'm using Python 3.3. I'm getting an email from an IMAP server, then
converting it to an instance of an email from the [standard email
library](http://docs.python.org/2/library/email.message.html).

I do this:

    
    
    message.get("date")
    

Which gives me this for example:

    
    
    Wed, 23 Jan 2011 12:03:11 -0700
    

I want to convert this to something I can put into `time.strftime()` so I can
format it nicely. I want the result in local time, not UTC.

There are so many functions, deprecated approaches and side cases, not sure
what is the modern route to take?


Answer: Something like this?

    
    
    >>> import time
    >>> s = "Wed, 23 Jan 2011 12:03:11 -0700"
    >>> newtime = time.strptime(s, '%a, %d %b %Y %H:%M:%S -0700')
    >>> print(time.strftime('Two years ago was %Y', newtime))
    Two years ago was 2011 # Or whatever output you wish to receive.
    

