Skip to main content
 首页 » 编程设计

python之AttributeError: 模块 'datetime' 没有属性 'time'

2025年05月04日22jyk

我正在使用 Python 3.7 并尝试从库中学习 datetime 模块,但我遇到了 AttributeError。代码如下:

import datetime 
 
t = datetime.time(4, 20, 1) 
 
# Let's show the different components 
print(t) 
print('hour  :', t.hour) 
print('minute:', t.minute) 
print('second:', t.second) 
print('microsecond:', t.microsecond) 
print('tzinfo:', t.tzinfo) 

作为运行文件,我收到此错误 AttributeError: module 'datetime' has no attribute 'time'

请帮我找出我哪里出错了。谢谢