python的时间换算
python 语言中,现在有字符串“11:45”,想计算现在时间同“11:45” 之间的秒数,应该怎么计算呢? 如果现在时间已经过了11点45分,就按照下一天的11:45 分来计算之间的秒数。谢谢大牛了!
from time import * time = "11:45".split(":") time = [int(s) for s in time] + [0] # time = [11, 45, 00] now = localtime() pnt = now[:3] + tuple(time) + now[6:] # pnt 就是同一天的 11:45:00 时刻。 diff = mktime(pnt) - mktime(now) if diff < 0 : diff += 24 * 60 * 60 print(diff)