【发布时间】:2009-06-10 19:30:49
【问题描述】:
如何使用 timeval 表示 10 毫秒?
这是我目前所拥有的:
struct timeval now;
now.tv_usec =10000;
【问题讨论】:
如何使用 timeval 表示 10 毫秒?
这是我目前所拥有的:
struct timeval now;
now.tv_usec =10000;
【问题讨论】:
struct timeval 将时间表示为秒数 (tv_sec) 加上 0 到 999,999 之间的微秒数 (tv_usec)。因此,要表示 10 毫秒,您将使用 10,000 微秒,正如您所建议的那样:
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 10000;
【讨论】:
对于将毫秒转换为 timeval 结构的更一般情况:
int milliseconds = 10;
struct timeval now;
now.tv_sec = milliseconds / 1000;
now.tv_usec = (milliseconds % 1000) * 1000;
【讨论】:
这是
struct timeval {
int tv_sec; // seconds
int tv_usec; // microseconds!
现在。
tv_sec = 0;
tv_usec = 10000;
` 是对的
【讨论】: