在几秒钟内使用monotonic()获得经过的时间

时间:2017-11-08 14:10:29

标签: python python-3.x

给定一个时间戳(作为字符串),我想在Python 3.6中使用Id输出经过的时间(以秒为单位)。

我试过了:

monotonic()

然而,这给出了一个负值,即task_start = '1510150124.133201' [long running code] time_taken = time.monotonic() - float(task_start) # -1510132274.84085 而不是以秒为单位的经过时间,为什么?

1 个答案:

答案 0 :(得分:3)

  

返回值的参考点未定义,因此只有连续调用结果之间的差异才有效。

这就是python文档所说的内容。由于time.monotonic()变量未使用<?php $UserID = 0; $UserName = "Mark"; $TalkingToUserID = 1; $TalkingToUserName = "Dalton"; $chatLog = fopen($UserID . "T" . $TalkingToUserID . ".txt", "w") or die("Unable to open file!"); function writeToFile($txt){ fwrite($chatLog, "\n" . $txt); fclose($chatLog); } writeToFile("Hello"); ?> 调用,因此无效。

相关问题