def seconds_until(until=9):
""" Counts the seconds until it is a certain hour again.
Keyword Arguments:
until (int): the hour we want to count to (default: {9})
Returns:
(float): how many seconds until the specified time.
"""
now = time.localtime()
now_sec = time.mktime(now)
if now.tm_hour >= until:
delta = (until * 60 * 60) \
+ (60 * 60 * (24 - now.tm_hour)) \
- (60 * now.tm_min) \
- (now.tm_sec)
else:
delta = (until * 60 * 60) \
- (60 * 60 * now.tm_hour) \
- (60 * now.tm_min) \
- (now.tm_sec)
then = time.localtime(now_sec + delta)
return time.mktime(then) - time.time()
评论列表
文章目录