1from datetime import datetime
2import time
3
4datetime1 = datetime.datetime.now()
5# Wait for 1 minute
6time.sleep(60)
7datetime2 = datetime.datetime.now()
8
9difference = datetime2 - datetime1
10print(f"The time difference between the 2 time is: {difference}")
1future_date = datetime.datetime(1970, 1, 2)
2past_date = datetime.datetime(1970, 1, 1)
3
4difference = (future_date - past_date)
5Calculate difference in time
6
7
8total_seconds = difference.total_seconds()
9Convert time difference to seconds
10
11
12print(total_seconds)
13OUTPUT
1486400.0
1import datetime as dt
2
3a = dt.datetime(2013,12,30,23,59,59)
4b = dt.datetime(2013,12,31,23,59,59)
5
6(b-a).total_seconds()