在Python中获得毫秒数 [英] Getting milliseconds in Python

查看:125
本文介绍了在Python中获得毫秒数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试记录一个操作需要多长时间,但似乎无法找到一个能让我记录时间戳的函数
毫秒,也许我在找错了地方?

解决方案

mjs7231写道:

我试图记录一个操作需要多长时间,但似乎无法找到一个允许我以毫秒记录时间戳的功能,也许我在找错了地方? / blockquote>


我不知道你在哪里看 - 但时间模块有恕我直言的描述性

足够的名字 - 所以看那里,快乐露营。


-

问候,


Diez B. Roggisch


"将时间作为以秒为单位表示的浮点数返回,以UTC为单位,以纪元为单位。请注意,即使时间总是以浮点数的形式返回,但并非所有系统都提供的时间精度比1秒更好。
精度。虽然此函数通常返回

非递减值,但如果系统时钟已在两次调用之间设置,则它可以返回比前一次调用更低的值




这不好,我正在寻找毫秒,而不是秒......如上所述

以上。


>>>>> " mjs7231" == mjs7231< mj ***** @ gmail.com>写道:


mjs7231>这不好,我正在寻找毫秒,而不是
mjs7231>秒..如上所述。


好​​秒/ 1000.0 =毫秒 - 或者您是否担心浮动

点错误?


7>>>从datetime导入日期时间

8>>> dt = datetime.now()

9>>> dt.microsecond

Out [9]:20222


另见timeit模块......

JDH


I am trying to record how long an operation takes, but can''t seem to
find a function that will allow me to record the timestamp in
milliseconds, maybe I am looking in the wrong place?

解决方案

mjs7231 wrote:

I am trying to record how long an operation takes, but can''t seem to
find a function that will allow me to record the timestamp in
milliseconds, maybe I am looking in the wrong place?



I have no idea where you look - but the time-module has IMHO a descriptive
enough name - so look there and be a happy camper.

--
Regards,

Diez B. Roggisch


"Return the time as a floating point number expressed in seconds since
the epoch, in UTC. Note that even though the time is always returned as
a floating point number, not all systems provide time with a better
precision than 1 second. While this function normally returns
non-decreasing values, it can return a lower value than a previous call
if the system clock has been set back between the two calls. "

This is no good, I am looking for milliseconds, not seconds.. as stated
above.


>>>>> "mjs7231" == mjs7231 <mj*****@gmail.com> writes:

mjs7231> This is no good, I am looking for milliseconds, not
mjs7231> seconds.. as stated above.

Well seconds/1000.0 = millseconds -- or are you worries about floating
point error?

7 >>> from datetime import datetime
8 >>> dt = datetime.now()
9 >>> dt.microsecond
Out[9]: 20222

Converting to milliseconds is left as an exercise for the reader...

See also the timeit module...
JDH


这篇关于在Python中获得毫秒数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆