欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python 获取时间的差

程序员文章站 2024-01-29 10:25:16
...
import datetime

today = datetime.datetime.today().replace(microsecond=0)
print(today)
outday = datetime.datetime(2019, 1, 22, 11, 58, 11)
print(outday)
days = (today - outday).days
seconds = (today - outday).seconds
minute, seconds = divmod(seconds, 60)
hour, minute = divmod(minute, 60)
surplus_hour = hour
surplus_minute = minute
surplus_time_str = '{}天{}小时{}分'.format(days, surplus_hour, surplus_minute)
print(surplus_time_str)

 

相关标签: 时间差 Python