如何解析格式为 +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>')
最佳答案
您可以使用 dateutil's parse为此:
from dateutil.parser import parse
s = '2019-04-10 21:49:41.607472+00'
parse(s)
datetime.datetime(2019, 4, 10, 21, 49, 41, 607472, tzinfo=tzutc())
关于具有 "+00"时区偏移格式的 Python strptime?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55639481/