I am getting the error above when I do:
datetime.strptime(item['dt'], "%Y-%m-%dT%H:%M:%S.%fZ")
Even if I try:
datetime.strptime(item['dt'], "%Y-%m-%dT%H:%M:%S.%f")
I am getting unconverted data remains: -04:00 as my error.
What am I doing wrong?
it's because you have 04:00 instead of 0400 for the utc offset...try this:
datetime.datetime.strptime('2019-06-02T16:19:27.000-0400', "%Y-%m-%dT%H:%M:%S.%f%z")
output:
datetime.datetime(2019, 6, 2, 16, 19, 27, tzinfo=datetime.timezone(datetime.timedelta(-1, 72000)))
%z
is expecting something like hhmm
https://docs.python.org/3/library/datetime.html - see format codes
根据datetime.strptime
的格式代码,您应该使用%z
来表示 UTC 偏移量:
datetime.strptime('2019-06-02T16:19:27.000-04:00', "%Y-%m-%dT%H:%M:%S.%f%z")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.