有一个开始时间和duration_Time如何计算结束时间

时间:2019-12-25 16:00:27

标签: python-3.x python-2.7

开始时间以小时(0..23)和分钟(0..59)对的形式给出。

例如,如果某个事件在12:17开始且持续时间为59分钟,那么它将在13:16结束,没有任何时间模块。

2 个答案:

答案 0 :(得分:0)

starttime = datetime.datetime(2019, 12, 25, 17, 4) # time now
delta = datetime.timedelta(minutes=5)  # could be minutes = whatever
endtime = starttime + delta

答案 1 :(得分:0)

hour = int(input("Starting time (hours): "))
mins = int(input("Starting time (minutes): "))
dura = int(input("Event duration (minutes): "))
mins = mins + dura # find a total of all minutes
hour = hour + mins // 60 # find a number of hours hidden in minutes and update the hour
mins = mins % 60 # correct minutes to fall in the (0..59) range
hour = hour % 24 # correct hours to fall in the (0..23) range
print(hour, ":", mins, Sep='')