python获取当日剩余时间,毫秒值、秒
今天写代码因为业务需要,计算了截止到目前当日剩余时间,网上这方面的资料比较少,发出来供大家参考
import datetime
import time
def rest_of_day():
"""
:return: 截止到目前当日剩余时间
"""
today = datetime.datetime.strptime(str(datetime.date.today()), "%Y-%m-%d")
tomorrow = today + datetime.timedelta(days=1)
nowTime = datetime.datetime.now()
return (tomorrow - nowTime).microseconds # 获取毫秒值
return (tomorrow - nowTime).seconds # 获取秒
return (tomorrow - nowTime).min # 获取分钟
if __name__ == '__main__':
print(rest_of_day())
运行结果:
88723
23887