我正在尝试使用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"是一个糟糕的指令.
任何解决方案的想法?
在系统 pendulum v1.4 的当前部分中使用,但使用 croniter 它会导致https://github.com/sdispater/pendulum/issues/214 中描述的错误
这适用于 datetime.datetime 类型,我仍然必须使用 pendulum v1.4。
所以我正在寻找如何有效地将钟摆转换为 datetime.datetime 类型的解决方案?
已经尝试将钟摆格式化为字符串并使用 dateutil.parser 进行解析。