2011-12-16 33 views
2

我是新手在Python中,我无法理解如何正确格式化日期。AttributeError:'time.struct_time'对象没有属性'toordinal'

我的数据是这样的Fri, 09 Dec 2011 06:50:37 UTC

我准备这样的:

dates.append(time.strptime(row[5], "%a, %d %b %Y %H:%M:%S %Z")) 

然后我尝试使用它

dates = matplotlib.dates.date2num(dates) 

得到以下错误:

AttributeError: 'time.struct_time' object has no attribute 'toordinal' 

回答

3

您正在使用time模块,但matplotlib需要datetime对象。

尝试使用这样的事情:

from datetime import datetime 

dates.append(datetime.strptime(row[5], "%a, %d %b %Y %H:%M:%S %Z")) 
... 
+0

感谢答案,但现在,我得到`AttributeError的:“模块”对象有没有属性“strptime'` – 2011-12-16 18:18:20