作为作业的一部分,我被要求根据自 1970 年 1 月 1 日以来经过的总秒数查找当前时间。我知道我们可以使用 time.time()
来获取秒数,但我我无法进入当前时间。
附件是我到目前为止的代码。
import time
a=time.time()
hours= (a)//3600
minutes=(a-hours*3600)/60
second=a%60
print(hours,"h",minutes,"m",second,"s")
请指教。
最佳答案
import time
current_time = time.ctime(int(time.time()))
print ("current_time:") + str(current_time)
输出:2012 年 6 月 28 日星期四 07:10:11 GMT
仅一次使用此:
import time
current_time = time.strftime("%H:%M", time.localtime(time.time()))
print("current_time:") + str(current_time)
关于python - 将 time.time() 秒转换为当前时间,格式为 hh :mm:ss in python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41583987/