[英]Converting date/time string into datetime object - format does not match
I'm trying to convert the string: 我正在尝试转换字符串:
'2018-10-16T11:41:39.29166592Z'
Into a datetime object using strptime. 使用strptime转换为datetime对象。 It seems the string format is wrong.
看来字符串格式是错误的。
Running the line below: 运行下面的行:
datetime.datetime.strptime('2018-10-16T11:41:39.29166592Z', '%Y-%m-%dT%H:%M:%S.%fZ')
outputs: 输出:
ValueError: time data '2018-10-16T11:41:39.29166592Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
ValueError:时间数据'2018-10-16T11:41:39.29166592Z'与格式'%Y-%m-%dT%H:%M:%S.%fZ'不匹配
Using the format: '%Y-%m-%dT%H:%M:%S.%9fZ'
doesn't work neither. 使用格式:
'%Y-%m-%dT%H:%M:%S.%9fZ'
都不起作用。
Thanks 谢谢
Try using the dateparser
module. 尝试使用
dateparser
模块。
Ex: 例如:
import dateparser
print(dateparser.parse('2018-10-16T11:41:39.29166592Z'))
Output: 输出:
2018-10-16 11:41:39.291665+00:00
Or dateutil
或
dateutil
Ex: 例如:
from dateutil.parser import parse
print(parse('2018-10-16T11:41:39.29166592Z'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.