一个时间结构的simple问题
struct timespec tm;
在表示绝对时间时,如
tm.tv_sec = time(NULL)+2;
tm.tv_sec = 0;
上边表示为2秒.如果想表示500毫秒怎么表示?用绝对时间.
问题点数:50、回复次数:3Top
1 楼kingofhell(地狱之王)回复于 2003-12-03 11:10:08 得分 0
upTop
2 楼fierygnu(va_list)回复于 2003-12-03 11:34:36 得分 20
什么叫绝对时间?当前时间过500ms?
tm.tv_sec = time(NULL);
tm.tv_nsec = 500 * 1000;Top
3 楼growup(Robin Guo)回复于 2003-12-03 18:19:03 得分 30
比较精确的:
struct timeval now;
gettimeofday(&now);
tm.tv_sec = now.tv_sec;
tm.tv_nsec = now.tv_usec * 1000 + 500 * 1000;
while (tm.tv_nsec >= 1000000) {
tm.tv_nsec -= 1000000;
tm.tv_sec += 1;
}
Top




