Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用单调()获取已用时间(以秒为单位)_Python_Python 3.x - Fatal编程技术网

Python 使用单调()获取已用时间(以秒为单位)

Python 使用单调()获取已用时间(以秒为单位),python,python-3.x,Python,Python 3.x,给定一个时间戳(作为字符串),我想使用Python 3.6中的monotonic()以秒为单位输出经过的时间 我试过: task_start = '1510150124.133201' [long running code] time_taken = time.monotonic() - float(task_start) # -1510132274.84085 但是,这会给出负值,即-1510132274.84085不是以秒为单位的经过时间,为什么 返回值的参考点未定义,因此只有连续调用结果

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

我试过:

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

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

python文档就是这么说的。由于您的
task\u start
变量未使用
time.monotonic()调用,因此它不起作用

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


python文档就是这么说的。由于您的
task\u start
变量未使用
time.monotonic()
调用,因此它不起作用。

task\u start
的此字符串值来自何处。为什么不
task\u start=time.monotonic()
?这个
task\u start
的字符串值来自哪里。为什么不
task\u start=time.monotonic()