读书人

Gcc 中的 gettimeofday 函数施用

发布时间: 2012-09-08 10:48:07 作者: rapoo

Gcc 中的 gettimeofday 函数使用
gettimeofday表头文件:#include <sys/time.h>函数原型:int gettimeofday(struct timeval *tv,struct timezone *tz)函数说明:把目前的时间按tv所指的结构返回,当时地区的信息则放到tz所指的结构中struct timeval{ long tv_sec; //秒 long tv_usec;//微妙}struct timezone{ int tz_minuteswest;//和格林威治时间差了多少分钟 int tz_dsttime; //日光节约时间的状态}
学习代码

#include <stdio.h>#include <sys/time.h>int main(int argc, char** argv){    timeval tv;    gettimeofday(&tv, NULL);    double cl = tv.tv_sec + (double)tv.tv_usec / 1000000;    getchar(); //暂停等待    gettimeofday(&tv, NULL);    cl = (tv.tv_sec + (double)tv.tv_usec / 1000000) - cl;    printf("暂停时间:%f\n", cl);    struct timezone tz;    gettimeofday(&tv, &tz);    printf("tv.tv_sec:%d\n", tv.tv_sec);    printf("tv.tv_usec:%d\n", tv.tv_usec);    printf("tz.tz_minuteswest:%d\n", tz.tz_minuteswest);    printf("tv.tz_dsttime:%d\n", tz.tz_dsttime);    return 0;}


读书人网 >编程

热点推荐