我有 2 个模块,第一个模块正在生成 ingestion_time
,如下所示
Long ingestion_time = System.currentTimeMillis();
此ingestion_time
的示例输出为
ingestion_time = 446453570778734
现在我在 python 中有第二个模块,它正在为同一事件生成 detector_time ,如下所示
detection_time = time.time()
此 detection_time
的示例输出为
detection_time = 1524807106.92
我希望它们具有相同的格式,以便我可以获得延迟
latency = detection_time - ingestion_time
两个模块位于同一系统上。
请帮忙!
<小时/>编辑 1
通过使用
now = long(time.time())
print "detection_time = %s "%now
我得到检测时间
为
detection_time = 1524808352
由于位数不同,仍然无法与 Generation_time
进行比较
generation_time = 1524808352170
<小时/>
回答
使用下面提到的代码解决了我的问题
now = int(round(time.time() * 1000))
print "detection_time = %s "%now
最佳答案
您需要的是获取以米秒为单位的时间。
import time
millis = int(round(time.time() * 1000))
print millis
为了重复使用:
import time
current_milli_time = lambda: int(round(time.time() * 1000))
然后:
>>> current_milli_time()
1378761833768
此答案已在here中找到
关于java - 在 Java 和 Python 中使用相同的时间格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50055849/