python - 将 time.time() 秒转换为当前时间,格式为 hh :mm:ss in python

标签 python

作为作业的一部分,我被要求根据自 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/

相关文章:

python - keras 中的自定义二进制交叉熵损失忽略没有非零值的列

python - 无法使用 opencv_contrib 3.2.0 构建 opencv 3.2.0

python索引错误: 2 lists that are inside a list

python - 转换器 wav 24 位到 16 位

python - PyO3 在 Rust 中实现 python 可迭代类

python - 为什么在 Transformer 模型中嵌入向量乘以一个常数?

python - 在 supervisord 下运行 python 时证书验证失败

python - 如何在没有 root 权限的情况下安装 python 3.x 和 2.y

python - Spyder 中的回退完成是什么?

python - 从表中提取特定数据