测量时间差
我想以毫秒为单位测量启动应用程序与另一个时间(例如 16:00 点)之间的时间间隔。最好的方法是什么?
我查看了“时钟”功能,但这不是我需要的。
操作系统:Win NT及以上
I want to measure in milliseconds how much time there is between when I start my application and another time, for example 16:00 o'clock. What is the best way to do this?
I looked around "clock" function but it's not what I need.
Operating system: Win NT and above
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查找 POSIX 系统的 gettimeofday ,以及 timeGetTime(适用于 Windows)。
编辑:OP似乎要求提供代码来将当前时间/日期与另一个时间/日期进行比较。以下代码片段演示了如何在 Windows 上获取当前日期和时间:
下面是如何计算两个 SYSTEMTIME 对象之间的差异:
这两个示例应该为您提供完成您需要的工具。
Look up gettimeofday for POSIX systems, and timeGetTime for Windows.
Edit: Seems the OP was asking for code to compare current time/date against another time/date. The following snippet demonstrates how to get current date and time on Windows:
And here's how to compute the difference between two SYSTEMTIME objects:
Those two samples should give you the tools to do what you need.
如果您使用的是 POSIX 系统,则可以使用
gettimeofday(3)
:如果您使用的是 Windows,则可以使用
GetTickCount
:但是要注意
GetTickCount
的分辨率只有大约 10-16 毫秒。如果您需要更高的精度,请使用QueryPerformanceCounter
和QueryPerformanceFrequency
相反:If you're on a POSIX system, you can use
gettimeofday(3)
:If you're on Windows, you can use
GetTickCount
:But but aware that
GetTickCount
only has a resolution of about 10-16 ms. If you need more precision, useQueryPerformanceCounter
andQueryPerformanceFrequency
instead: