让我有想法在Python中实现以下功能
total_hrs = datetime.timedelta(hours=total_hrs)
这将导致3:52:30。但我需要减少秒数。这应该是3:52:00的格式
答案 0 :(得分:3)
result = datetime.timedelta(minutes=int(total_hours*60))
答案 1 :(得分:1)
total_hrs = datetime.timedelta(hours=3.875)
print str(total_hrs)
>>> 3:52:30
# Split into components
total_hrs_split = str(total_hrs).split(':')
print total_hrs_split
>>> ['3', '52', '30']
# Trim off seconds
total_hrs_trimmed=datetime.timedelta(hours=int(total_hours_split[0]),
minutes=int(total_hours_split[1]))
print str(total_hrs_trimmed)
>>> 3:52:00