import time, datetime
from datetime import date
date1 = "2021-10-1"
date2 = "2020-9-15"
date1 = time.strptime(date1, "%Y-%m-%d")
date2 = time.strptime(date2, "%Y-%m-%d")
date1 = datetime.datetime(date1[0], date1[1], date1[2])
date2 = datetime.datetime(date2[0], date2[1], date2[2])
day = date1 - date2
print(day.days)
381
date1 = date(2021, 10, 1)
date2 = date(2020, 5, 6)
x = date1.__sub__(date2)
print(x.days)
513
# 时间间隔2秒
date1 = datetime.datetime.now()
time.sleep(2)
date2 = datetime.datetime.now()
x = date2.__sub__(date1)
print(x.seconds)
# 字符串日期格式化
date1 = "2021-10-1"
date1 = time.strptime(date1, "%Y-%m-%d")
date1 = datetime.date(date1[0], date1[1], date1[2])
https://www.cnblogs.com/xudongliang/p/12467592.html
https://blog.csdn.net/weixin_41261833/article/details/103909724