Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to get mid time of given time in python

# hour and minutes only
sh, sm = map(int, input().split(':')) # start time
eh, em = map(int, input().split(':')) # end time

if sh > eh or (sh == eh and sm > em):
# converting time into minutes
    mid_m = (((sh * 60) + sm) + (1440 + (eh * 60) + em)) // 2      
else:
    mid_m = (((sh * 60) + sm) + ((eh * 60) + em)) // 2
    
if mid_m >= 1440:
    mid_m = mid_m - 1440
mh = mid_m // 60
mm = mid_m - (mh * 60)

if mh < 10:
    mh = '0' + str(mh)
if mm < 10:
    mm = '0' + str(mm)
print(mh, ':', mm, sep='')
 
PREVIOUS NEXT
Tagged: #mid #time #time #python
ADD COMMENT
Topic
Name
9+1 =