相关疑难解决方法(0)

使用strptime将带有offset的时间戳转换为datetime obj

我正在尝试使用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"是一个糟糕的指令.

任何解决方案的想法?

python datetime timestamp rfc3339

49
推荐指数
3
解决办法
3万
查看次数

标签 统计

datetime ×1

python ×1

rfc3339 ×1

timestamp ×1