时间戳的小数部分是什么?

Jos*_*eph 2 python python-2.7 python-3.x python-datetime

我在python中运行以下代码,

import time
print(time.time())
Run Code Online (Sandbox Code Playgroud)

输出是:

1557990717.6383634

谁能解释一下小数点左右两部分。为什么有小数点?

fun*_*200 5

官方文档所述time.time()返回一个浮点数,表示自纪元以来的秒数。点左边的数字代表秒,右边的数字代表秒之间的毫秒数。

如果您只想要自纪元以来的秒数,您可以使用:

round(time.time())
Run Code Online (Sandbox Code Playgroud)

如果你只想要毫秒部分,你可以使用:

time.time() % 1
Run Code Online (Sandbox Code Playgroud)