如何使用timeval表示10毫秒?
这就是我到目前为止所知道的:
struct timeval now;
now.tv_usec =10000; 发布于 2009-06-10 19:33:07
struct timeval将时间表示为秒数(tv_sec)加上介于0和999,999,999之间的微秒数(tv_usec)。因此,要表示10毫秒,您将使用10,000微秒,正如您所建议的那样:
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 10000;发布于 2013-10-29 23:02:56
对于将毫秒转换为timeval结构的更一般情况,请使用:
int milliseconds = 10;
struct timeval now;
now.tv_sec = milliseconds / 1000;
now.tv_usec = (milliseconds % 1000) * 1000;发布于 2009-06-10 19:34:17
它是
struct timeval {
int tv_sec; // seconds
int tv_usec; // microseconds!所以现在。
tv_sec = 0;
tv_usec = 10000; ‘将会是正确的
https://stackoverflow.com/questions/977684
复制相似问题