cdkeycdma 发表于 2020-9-6 17:41:36

为何这个代码跑不过?

from datetime import datetime
a= datetime.now()
dt1=a+datetime.timedelta(hours=1)
print(dt1)

提示:
Traceback (most recent call last):
File "E:/pyhton/random_walk.py", line 3, in <module>
    dt1=a+datetime.timedelta(hours=1)
AttributeError: type object 'datetime.datetime' has no attribute 'timedelta'

kogawananari 发表于 2020-9-6 17:46:09

import datetime
a= datetime.datetime.now()
dt1=a+datetime.timedelta(hours=1)
print(dt1)

datetime模块下面有5大类 (抽象类tzinfo就不说了)
datetime.timedelta        时间间隔类
datetime.timezone        时区信息类
datetime.date        简单型日期类
datetime.time        时间类
datetime.datetime        date类的子类,日期时间类
页: [1]
查看完整版本: 为何这个代码跑不过?