import time
import os
"""请算到指定时间的倒时计"""
def quit_system(t):
"""
:param t: 关机时间例子18:20
:return: 秒,分
"""
# 本地时间
start_time = time.localtime()
# 指定时间戳
to_time = '%s-%s-%s %s:00' % (start_time.tm_year,start_time.tm_mon,start_time.tm_mday,t)
# 时间数组
timeArray = time.strptime(to_time, "%Y-%m-%d %H:%M:%S")
# ______________转为时间戳 大的
endt = time.mktime(timeArray)
# 计算开机时间还剩多久到关机时间 秒
a = endt - time.time()
# 结果转为 分钟
result = int(a)/60
return a,result
if __name__ == '__main__':
m, se = quit_system('16:29')
print("距离指定时间约为%d分钟,共%d秒" % (se,m))