python time diff code example
Example 1: python difference in time
from datetime import datetime
import time
datetime1 = datetime.datetime.now()
time.sleep(60)
datetime2 = datetime.datetime.now()
difference = datetime2 - datetime1
print(f"The time difference between the 2 time is: {difference}")
Example 2: get time between things python
>>> import datetime
>>> time1 = datetime.datetime.now()
>>> time2 = datetime.datetime.now()
>>> elapsedTime = time2 - time1
>>> elapsedTime
datetime.timedelta(0, 125, 749430)
>>> divmod(elapsedTime.total_seconds(), 60)
(2.0, 5.749430000000004)