Parse xsd:dateTime formatted string to python datetime
Question: Given a string in [xsd:dateTime
format](http://books.xmlschemata.org/relaxng/ch19-77049.html) I want to create
a python datetime object. I especially need to be able to parse for example a
string like this '2012-09-23T09:55:00', but also all other defined examples
should be parsed correctly, and also use timezones.


Answer: Use the [`datetime.datetime.strptime` class
method](http://docs.python.org/library/datetime.html#datetime.datetime.strptime)
to parse these:

    
    
    dt = datetime.datetime.strptime(xsdDateTime, '%Y-%m-%dT%H:%M:%S')
    

Your example does _not_ include a timezone however. If you really do need
timezone support, best resort to the [`python-dateutil`
module](http://labix.org/python-
dateutil#head-c0e81a473b647dfa787dc11e8c69557ec2c3ecd2):

    
    
    from dateutil.parser import parse
    dt = parse(xsdDateTime)
    

