Python - Convert string representation of date to ISO 8601

后端 未结 2 507
南笙
南笙 2020-12-01 09:59

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?

2条回答
  •  心在旅途
    2020-12-01 10:58

    Using dateutil:

    import dateutil.parser as parser
    text = 'Thu, 16 Dec 2010 12:14:05 +0000'
    date = parser.parse(text)
    print(date.isoformat())
    # 2010-12-16T12:14:05+00:00
    

提交回复
热议问题