用日期时间做减法的正确方法是什么

What is a proper way of doing a substraction with datetime

我有一个日期时间变量,我想从中减去 1 小时。我试图用下面的代码来做,但我收到了以下错误:TypeError: unsupported operand type(s) for -: 'str' and 'datetime.timedelta'

from datetime import datetime, timedelta

cur_time = datetime.now()
cur_time_f = cur_time.strftime("%Y-%m-%dT%H:%M:%SZ")  
print(cur_time_f)

>> 2020-09-15T09:07:44Z

nueve = cur_time_f - timedelta(hours=1)

print(nueve)

我的预期输出:

>> 2020-09-15T08:07:44Z

在将其转换为字符串之前进行计算

from datetime import datetime, timedelta

cur_time = datetime.now()
print(cur_time)

>>2020-09-15 11:29:51.756391

cur_time = cur_time - timedelta(hours=1)
cur_time_f = cur_time.strftime("%Y-%m-%dT%H:%M:%SZ")  
print(cur_time_f)

>>2020-09-15T10:29:51Z