这将适用于 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'
感谢你的支持。
从日期时间导入日期从时间导入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