下面代码计算两个给定日期之间的天数 -
#!/usr/bin/python3
#coding=utf-8
import time
import datetime
d1 = datetime.datetime(2018, 10, 18)
d2 = datetime.datetime(2017, 12, 31)
print ( (d1 - d2).days)
## 当前日期
curdate = datetime.date.today()
print ("curdate = ", curdate)
执行上面代码,得到以下结果 -
291
curdate = 2018-10-21
上一篇:
Python日期和时间
下一篇:
Python函数