Python strptime 具有“+00”时区偏移格式?

Jam*_*zba 4 python time timezone date

如何使用 format 解析时区偏移量+00?Python 3 或 Python 2

from datetime import datetime
s = '2019-04-10 21:49:41.607472+00'
# What must I replace <XX> with, to parse +00 as the timezone offset
d = datetime.strptime(s, '%Y-%m-%d %H:%M:%S.%f<XX>')
Run Code Online (Sandbox Code Playgroud)

Raj*_*jan 5

您可以使用dateutil 的解析

from dateutil.parser import parse
s = '2019-04-10 21:49:41.607472+00'
parse(s)
Run Code Online (Sandbox Code Playgroud)

datetime.datetime(2019, 4, 10, 21, 49, 41, 607472, tzinfo=tzutc())