Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x AttributeError:type object';datetime.datetime';没有属性';时间差';_Python 3.x - Fatal编程技术网

Python 3.x AttributeError:type object';datetime.datetime';没有属性';时间差';

Python 3.x AttributeError:type object';datetime.datetime';没有属性';时间差';,python-3.x,Python 3.x,如果我从att2中删除了datetime,则会对att3生效 att3=(att1-时间0+att2).strftime(“%X%p”) AttributeError:“datetime.timedelta”对象没有属性“strftime” 错误 回溯(最近一次呼叫最后一次): 文件“addtwotimes.py”,第5行,在 from datetime import datetime, time, timedelta att1 = datetime.strptime('09:00 AM','

如果我从att2中删除了datetime,则会对att3生效 att3=(att1-时间0+att2).strftime(“%X%p”) AttributeError:“datetime.timedelta”对象没有属性“strftime”

错误

回溯(最近一次呼叫最后一次):

文件“addtwotimes.py”,第5行,在

from datetime import datetime, time, timedelta

att1 = datetime.strptime('09:00 AM','%H:%M %p')

att2 = datetime.timedelta(minutes = 15)

time_zero = datetime.strptime('00:00 AM','%H:%M %p')

att3 =  (att1 - time_zero + att2).strftime("%X %p")

print(" sTime and Approx time is",att3)
AttributeError:类型对象“datetime.datetime”没有属性 “时间增量”


您导入了timedelta,您可以像
timedelta
一样使用它。当您执行导入日期时间时,使用
datetime.timedelta
att2=datetime.timedelta(分钟='15')
更改为
att2=timedelta(分钟='15')
,因为您已经将timedelta导入为
从datetime导入timedelta
可能重复的@RahulRaut:它必须是
att2=timedelta(分钟=15)
(int,而不是string)。不过OP已经更正了类型。另外,
att3=(att1-time\u zero+att2)。strftime(“%X%p”)
不起作用,因为timedelta没有方法
strftime()
。格式化timedelta有点困难,请参见示例。
att2 = datetime.datetime(minutes = 15)