将unicode转换为datetime适当的strptime格式 [英] Convert unicode to datetime proper strptime format
本文介绍了将unicode转换为datetime适当的strptime格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我阅读了文档: http://docs.python.org/2/library/time.html#time.strptime
并尝试
datetime.strptime(date_posted,'%Y-%m-% dT%H:%M:%SZ')
但是我收到错误消息 ValueError:time data'2014-01-15T01:35:30.314Z'与格式不相符'%Y-%m-%dT%H:%M:%SZ'
对什么是正确格式的任何反馈?
我感谢时间和专长。
解决方案
您可以解析微秒:
from datetime import datetime
date_posted ='2014-01-15T01:35:30.314Z'
datetime.strptime(date_posted,'%Y-%m-%dT%H:%M:%S.%fZ ')
I am trying to convert a unicode object to a datetime object.
I read through the documentation: http://docs.python.org/2/library/time.html#time.strptime
and tried
datetime.strptime(date_posted, '%Y-%m-%dT%H:%M:%SZ')
but I get the error message ValueError: time data '2014-01-15T01:35:30.314Z' does not match format '%Y-%m-%dT%H:%M:%SZ'
Any feedback on what is the proper format?
I appreciate the time and expertise.
解决方案
You can parse the microseconds:
from datetime import datetime
date_posted = '2014-01-15T01:35:30.314Z'
datetime.strptime(date_posted, '%Y-%m-%dT%H:%M:%S.%fZ')
这篇关于将unicode转换为datetime适当的strptime格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文