美文网首页
python获取当日剩余时间

python获取当日剩余时间

作者: 一灰丶 | 来源:发表于2019-02-25 17:24 被阅读0次

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

相关文章

网友评论

      本文标题:python获取当日剩余时间

      本文链接:https://www.haomeiwen.com/subject/gyigyqtx.html