Python计算两个日期相隔的差值天数

# 计算两个日期差值
def day_diff(start_time, end_time):
    start = time.mktime(time.strptime(start_time, '%Y-%m-%d'))
    end = time.mktime(time.strptime(end_time, '%Y-%m-%d'))
    days = int((end - start) / (60 * 60 * 24))
    return days
 
s = '2022-01-15'
e = time.strftime('%Y-%m-%d', time.localtime())
print(s, e)
 
r = day_diff(s, e)
print(r)

 

你可能感兴趣的