如何使用timeval表示10毫秒?
这是我到目前为止:
struct timeval now;
now.tv_usec =10000;
Run Code Online (Sandbox Code Playgroud)
Ada*_*eld 27
A struct timeval表示时间,以秒数(tv_sec)加上tv_usec0到999,999之间的微秒数().因此,要表示10毫秒,您将使用10,000微秒,如您所建议:
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 10000;
Run Code Online (Sandbox Code Playgroud)
Smi*_*ver 13
有关将毫秒转换为timeval struct的更一般情况,请使用:
int milliseconds = 10;
struct timeval now;
now.tv_sec = milliseconds / 1000;
now.tv_usec = (milliseconds % 1000) * 1000;
Run Code Online (Sandbox Code Playgroud)
它的
struct timeval {
int tv_sec; // seconds
int tv_usec; // microseconds!
Run Code Online (Sandbox Code Playgroud)
所以现在.
tv_sec = 0;
tv_usec = 10000;
Run Code Online (Sandbox Code Playgroud)
`是对的
| 归档时间: |
|
| 查看次数: |
14986 次 |
| 最近记录: |