我正在尝试使用strptime方法将格式为"2012-07-24T23:14:29-07:00"的时间戳转换为python中的datetime对象.问题在于结束时的时间偏移(-07:00).没有偏移我可以成功做到
time_str = "2012-07-24T23:14:29"
time_obj=datetime.datetime.strptime(time_str,'%Y-%m-%dT%H:%M:%S')
Run Code Online (Sandbox Code Playgroud)
但随着我尝试的抵消
time_str = "2012-07-24T23:14:29-07:00"
time_obj=datetime.datetime.strptime(time_str,'%Y-%m-%dT%H:%M:%S-%z').
Run Code Online (Sandbox Code Playgroud)
但是它给出了一个Value错误,说"z"是一个糟糕的指令.
任何解决方案的想法?
我收到以下错误:
time data '07/28/2014 18:54:55.099000' does not match format '%d/%m/%Y %H:%M:%S.%f'
Run Code Online (Sandbox Code Playgroud)
但是我看不出哪个参数错了%d/%m/%Y %H:%M:%S.%f?
这是我使用的代码.
from datetime import datetime
time_value = datetime.strptime(csv_line[0] + '000', '%d/%m/%Y %H:%M:%S.%f')
Run Code Online (Sandbox Code Playgroud)
我添加并删除了000但是我得到了同样的错误.