-2

I wrote this code:

chegada = input('Enter arrival time: "Hours: Minutes" ')
saida = input('Inform the time of departure: "Hours: Minutes" ')

fmt = '%H:%M'
tdelta = datetime.strptime(saida, fmt) - datetime.strptime(chegada, fmt)
if tdelta.days < 0:
    tdelta = timedelta(days=0, seconds=tdelta.seconds,
        microseconds=tdelta.microseconds)

Now i wanted to know how to convert in seconds

Pand
  • 25
  • 4

1 Answers1

0
from datetime import datetime
from datetime import timedelta

chegada = input('Enter arrival time: "Hours: Minutes" ')
saida = input('Inform the time of departure: "Hours: Minutes" ')

fmt = '%H:%M'
tdelta = datetime.strptime(saida, fmt) - datetime.strptime(chegada, fmt)
if tdelta.days < 0:
    tdelta = timedelta(days=0, seconds=tdelta.seconds,
        microseconds=tdelta.microseconds)
print(tdelta)
print(tdelta.total_seconds())
Shabari nath k
  • 920
  • 1
  • 10
  • 23