我正在尝试实现这个时间类来查找当前时间。我走错时间了。有人能看看我做错什么了吗?你知道吗
import time
import datetime
class Time():
def __init__(self):
currentTime = time.time()
totalSeconds = int(currentTime)
self.__second = totalSeconds % 60
totalMinutes = totalSeconds // 60
self.__minute = totalMinutes %60
totalHours = totalMinutes// 60
self.__hour = totalHours % 12
def getSecond(self):
return self.__second
def getMinute(self):
return self.__minute
def getHour(self):
return self.__hour
def main():
t = Time()
print("Current Time is : ", t.getHour(), ":", t.getMinute(), ":", t.getSecond())
print(datetime.datetime.now().time())
print(time.ctime())
main()
您的代码总是处理UTC时间,但是您正在将结果与时区中的时间进行比较。试试这个:
相关问题 更多 >
编程相关推荐