Timedelta multiply with float in python
You can convert to total seconds and back again:
full_time = timedelta(seconds=multiplier * passed_time.total_seconds())
timedelta.total_seconds
is available from Python 2.7; on earlier versions use
def timedelta_total_seconds(td): return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / float(10**6)
You could use total_seconds()
:
datetime.timedelta(seconds=datetime.timedelta(minutes=42).total_seconds() * 0.8)# => datetime.timedelta(0, 2016)