这将在python 2.6中运行
from datetime import datetime
print (datetime.strptime('2008-12-31', "%Y-%m-%d")- datetime.strptime('2007-04-30',"%Y-%m-%d")).days
但在2.4中显示以下错误
AttributeError: type object 'datetime.datetime' has no attribute 'strptime'
感谢您的支持。
从datetime导入日期开始 从时间导入strptime
x= strptime('2008-12-31', "%Y-%m-%d")
y= strptime('2007-04-30', "%Y-%m-%d")
print (date(x.tm_year,x.tm_mon,x.tm_mday)- date(y.tm_year,y.tm_mon,y.tm_mday)).days
答案 0 :(得分:7)
在Python 2.4中,strptime位于时间模块中:
from time import strptime