时间戳字符串到日期时间 (python)

Timestamp string to datetime (python)

我有这个时间戳字符串:

x = 2021-11-24T16:05:51.399+0000

我正在努力让解析在小数点后通过。到目前为止,这是我的尝试:

datetime.datetime.strptime(x,"%Y-%m-%dT%H:%M:%S.%f+")

当前错误运行这一行:

ValueError: unconverted data remains: 0000

在格式末尾添加%z以匹配UTC offset in the form ±HHMM[SS[.ffffff]] (empty string if the object is naive).

>>> from datetime import datetime
>>>
>>> x = '2021-11-24T16:05:51.399+0000'
>>> datetime.strptime(x,"%Y-%m-%dT%H:%M:%S.%f%z")
datetime.datetime(2021, 11, 24, 16, 5, 51, 399000, tzinfo=datetime.timezone.utc)