如何将'2006-11-06T09:49:43.000+08:00'之类的时间类型转换为年月日小时:分钟:秒
How to conver the time type like '2006-11-06T09:49:43.000+08:00' to year-month-day hour: minutes: seconds
import time
temp_time ='2006-11-06T09:49:43.000+08:00'
time.strftime("%Y-%m-%d %H:%M:%S",temp_time)
我收到如下错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-17-97b64e318f17> in <module>()
1 import time
2 temp_time ='2006-11-06T09:49:43.000+08:00'
----> 3 time.strftime("%Y-%m-%d %H:%M:%S",temp_time)
TypeError: Tuple or struct_time argument required
\任何帮助将不胜感激。
首先用strptime()
将字符串转换为时间对象。
>>> import time
>>> temp_time = '2006-11-06T09:49:43.000+08:00'
>>> s_time = time.strptime(temp_time, "%Y-%m-%dT%H:%M:%S.000+08:00")
>>> time.strftime("%Y-%m-%d %H:%M:%S", s_time)
'2006-11-06 09:49:43'
import time
temp_time ='2006-11-06T09:49:43.000+08:00'
time.strftime("%Y-%m-%d %H:%M:%S",temp_time)
我收到如下错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-17-97b64e318f17> in <module>()
1 import time
2 temp_time ='2006-11-06T09:49:43.000+08:00'
----> 3 time.strftime("%Y-%m-%d %H:%M:%S",temp_time)
TypeError: Tuple or struct_time argument required
\任何帮助将不胜感激。
首先用strptime()
将字符串转换为时间对象。
>>> import time
>>> temp_time = '2006-11-06T09:49:43.000+08:00'
>>> s_time = time.strptime(temp_time, "%Y-%m-%dT%H:%M:%S.000+08:00")
>>> time.strftime("%Y-%m-%d %H:%M:%S", s_time)
'2006-11-06 09:49:43'