total_seconds method of Python timedelta class

The total number of seconds represented by a timedelta object is returned by the total_seconds() method. The python code example returns the number of seconds for the duration of one day.

Timedelta Updated 20 Jan 2019 1 min read

Method Name

total_seconds

Method Signature

total_seconds()

Overview

Returns the duration represented by the timedelta object as number of seconds.

Parameters

None

Example

python
import datetime

# Create a time duration of one day

timeDuration = datetime.timedelta(days=1)

print("Time duration:%s"%(timeDuration))

print("Time duration as seconds:%s"%(timeDuration.total_seconds()))

Output

Output
Time duration:1 day, 0:00:00

Time duration as seconds:86400.0