python - Finding elapsed time across midnight without dates -


how compute elapsed time between time1 = 23:30:00 , time2 = 01:30:00? not have dates associated them, python attaches date 1900-01-01 when make them datetime objects, become time1 = 1900-01-01 23:30:00 , time2 = 1900-01-01 01:30:00. desired outcome 2 hours.

you can subtract 2 datetime objects , difference between them

from datetime import datetime  # d = datetime(year, month, day, hour, min, sec) d1 = datetime(2017, 9, 1, 23, 30, 00) d2 = datetime(2017, 9, 2, 1, 30, 00) print d2 - d1 

2:00:00


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -