Posts pythonTip 22 时间就是金钱
Post
Cancel

pythonTip 22 时间就是金钱

题目描述:

给你两个时间st和et(00:00:00<=st <= et<=23:59:59), 请你给出这两个时间间隔的秒数。 如:st=”00:00:00”, et=”00:00:10”, 则输出10.

分析

我在这里时间把时间 转换成秒,然后取差值。

h_s, m_s, s_s = st.split(":")
h_e, m_e, s_e = et.split(':')

time_s = 3600 * int(h_s) + 60 * int(m_s) + int(s_s)
time_e = 3600 * int(h_e) + 60 * int(m_e) + int(s_e)

print(abs(time_s - time_e))
This post is licensed under CC BY 4.0 by the author.
Trending Tags
Contents

pythonTip 21 回文子串

pythonTip 23 365Or366

Trending Tags