我不是为什么我在下面的代码中出错-
from datetime import datetime
import time
start =datetime.now().replace(microsecond=0).isoformat(' ')
end = datetime.now().replace(microsecond=0).isoformat(' ')
print(f" Total Time taken by check run is {end - start}[hh:mm:ss]")
打印声明中出现错误:
TypeError: unsupported operand type(s) for -: 'str' and 'str'
isoformat()
返回一个string
。
如果从datetime object
中删除isoformat()
,则可以减去时间差。
start = datetime.now().replace(microsecond=0)
end = datetime(2021, 4, 9, 17, 15, 00)
print(f" Total Time taken by check run is {end - start}[hh:mm:ss]")
#Total Time taken by check run is 1:26:18[hh:mm:ss]