Alon Gubkin Alon Gubkin - 2 years ago 139
Python Question

Python - Convert date to ISO 8601

In Python, how can I convert a string like this:

Thu, 16 Dec 2010 12:14:05 +0000

to ISO 8601 format, while keeping the timezone?

Please note that the orginal date is string, and the output should be string too, not
or something like that.

I have no problem to use third parties libraries, though.

Answer Source

Using dateutil:

import dateutil.parser as parser
text = 'Thu, 16 Dec 2010 12:14:05 +0000'
date = (parser.parse(text))
# 2010-12-16T12:14:05+00:00
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download