gpt4 book ai didi

python - 属性错误 : type object 'datetime.time' has no attribute 'mktime'

转载 作者:行者123 更新时间:2023-12-04 17:55:55 27 4
gpt4 key购买 nike

我收到此属性错误,要么是因为我正在导入模块,要么是错误地引用了它们。

from datetime import date, timedelta, datetime, time, tzinfo

def utc2local (utc):
epoch = time.mktime(utc.timetuple())
offset = datetime.fromtimestamp (epoch) - datetime.utcfromtimestamp (epoch)
return utc + offset

调用者

(utc2local(rise), utc2local(set))

这给了我 - AttributeError: type object 'datetime.time' has no attribute 'mktime'

我已经将导入更改为

import time
from datetime import date, timedelta, datetime, tzinfo

但我得到 - TypeError: 'module' object is not callable

我应该如何调用模块或者我应该使用什么来引用它们,谢谢

最佳答案

你不需要导入日期时间就这样做吧:

import time
time.mktime(your_time)

from time import mktime
mktime(t)

来源:https://www.tutorialspoint.com/python/time_mktime.htm

关于python - 属性错误 : type object 'datetime.time' has no attribute 'mktime' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40439398/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com