import datetime

def is_between_8_to_8_15():
    now = datetime.datetime.now().time()
    start = datetime.time(8, 0, 0)
    end = datetime.time(8, 15, 0)
    return start <= now <= end

使用方法:

if is_between_8_to_8_15():
    print("当前时间在上午8点到8点15分之间")
else:
    print("当前时间不在上午8点到8点15分之间")
用python写一个函数判断当前时间是否在上午8点钟到8点15分之间

原文地址: https://www.cveoy.top/t/topic/hsOq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录