Python:将时间模块转换为字符串

标签 python time

我在一段 python 代码中有一个字符串,我也想添加一个时间戳。但是,当我尝试将时间戳转换为字符串时,我得到的是数据类型,而不是时间戳的字符串表示形式。

代码是这样的

timeStamp = "TIME-" + str(time)
print timeStamp

>>> Time-<module 'time' (built-in)>

如何将时间戳转换为字符串以允许它与另一个字符串连接?

最佳答案

您只导入了 time 模块并将that 转换为字符串;你需要调用time.time() function :

timeStamp = "TIME-" + str(time.time())

关于Python:将时间模块转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23247983/

相关文章:

algorithm - 游泳混合泳接力时间模拟算法

python - 在python中使用time sleep方法时出错

c - 在 C 问题中使用 time() 和 clock()

python - 如何调试 "FileNotFoundError: [WinError 2] The system cannot find the file specified"?

python - 使用列名创建一个空数据框或列表,然后按列名添加数据

python - 如何在 python + linux 中监听端口并行

c - 函数的隐式声明 'clock'

python - 只查找属性完全匹配的 HTML 节点

python - 如何将Excel工作簿中的所有工作表保存为一个文本文件?

python - 准确测量python函数花费的时间