我想创建一个计算剩余小时数和分钟数的程序
例如
18:30 - 19:10 - > 0小时40分钟
class Uhrzeit():
def __init__(self, von, bis):
self.von = von
self.bis = bis
self.umrechnen()
def umrechnen(self):
master = 60
stunden_bis,stunden_von = int(self.bis.split(":")[0]),int(self.von.split(":")[0])
minuten_bis,minuten_von = int(self.bis.split(":")[1]),int(self.von.split(":")[1])
print stunden_bis-stunden_von, minuten_bis-minuten_von
Uhrzeit("18:30","19:10")
>> 1 -20
答案 0 :(得分:0)
您可以使用日期时间模块,这使事情变得非常简单。
from datetime import datetime
time1 = datetime.strptime("18:30", "%H:%M")
time2 = datetime.strptime("19:10", "%H:%M")
diff = time2 - time1
print(diff)
零时40分00秒