0

I have this small piece of code that keeps track of the runtime of a script:

startTime = datetime.now()
time = datetime.now() - startTime
return time

The type of "time" is "datetime.timedelta" and the output is "0:00:13.084000". I'm interested only in the seconds (13).

How can I extract that piece of information?

Benjamin
  • 315
  • 2
  • 14

1 Answers1

1

Your object is a datetime.timedelta instance, so use time.seconds for the seconds field only, or time.total_seconds() for all the time duration, converted to seconds (They're different things)

bakkal
  • 54,350
  • 12
  • 131
  • 107