Python 以小时为单位获取Datetime之间的差异,将两个四舍五入设置为2
通过四舍五入到小数点后2位,获得两个datetime之间以小时为单位的差值Python 以小时为单位获取Datetime之间的差异,将两个四舍五入设置为2,python,pandas,numpy,dataframe,datetime,Python,Pandas,Numpy,Dataframe,Datetime,通过四舍五入到小数点后2位,获得两个datetime之间以小时为单位的差值 > `Started Ended` Hours 2020-10-01 09:29:20 2020-10-01 17:43:28 8.2 2020-10-31 09:26:43 2020-10-31 18:57:40 9.5 2020-10-31 09:18
> `Started Ended` Hours
2020-10-01 09:29:20 2020-10-01 17:43:28 8.2
2020-10-31 09:26:43 2020-10-31 18:57:40 9.5
2020-10-31 09:18:57 2020-10-31 21:06:30 11.8
与and一起使用,最后除以and使用:
另一个例子:
from datetime import datetime
beg = '08:00:10'
end = '17:16:24'
print('end = ',end, 'type: ',type(end))
dur = datetime.strptime(end, '%H:%M:%S') - datetime.strptime(beg, '%H:%M:%S')
result = dur.total_seconds()/3600
result = round(result, 2)
print(result)
from datetime import datetime
beg = '08:00:10'
end = '17:16:24'
print('end = ',end, 'type: ',type(end))
dur = datetime.strptime(end, '%H:%M:%S') - datetime.strptime(beg, '%H:%M:%S')
result = dur.total_seconds()/3600
result = round(result, 2)
print(result)