Python 2.4中两个日期之间的天数
这个在 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
1 个回答
7
在Python 2.4中,strptime这个功能是在时间模块里面的:
from time import strptime
可以查看这个链接了解更多信息:http://docs.python.org/release/2.4/lib/module-time.html