#inlcude<error.h>
errno
perror(); //打印错误
strerror //打印错误
#inlcude<time.h>
//使用CLOCKS_PER_SEC //常量可以得到秒数
clock_t \\ typedef long clock_t;
clock_t clock(void) //只是检测处理器的时间,如果睡眠不算。即进程占用cpu时间。
clock_t clk_start ,clk_end;
clk_start = clock();
.........
clk_end = clock();
int clk = clk_end - clk_start;
---------------------------------------------------------------------
time_t //日历时间 typedef long time_t
time_t time(time_t *tloc);//参数可以为NULL, srand(time(NULL)); //设置随机因子 rand();
time_t t1,t2;
t1 = time (&t2);
t1 = t2;
-----------------------------------
char* ctime(&t1); //把time_t转为一个字符串
int stime(time_t *t);
t1 =time(NULL); //获取时间
t1 +=(24*60*60)UL; //增加时间
stime(&t1); //设置时间
printf... ctime(&t1); //打印时间
struct tm //分解时间
struct tm {
int tm_sec; /* Seconds (0-60) */
int tm_min; /* Minutes (0-59) */
int tm_hour; /* Hours (0-23) */
int tm_mday; /* Day of the month (1-31) */
int tm_mon; /* Month (0-11) */
int tm_year; /* Year - 1900 */
int tm_wday; /* Day of the week (0-6, Sunday = 0) */
int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
int tm_isdst; /* Daylight saving time */
};
//------------------------内核 定时器也有个时间结构体 struct timer_list
//定一个定时器
struct timer_list my_timer;
//初始化定时器
void init_timer(struct timer_list *timer);
mytimer.function = my_function;
mytimer.expires = jiffies +HZ;
//增加定时器
void add_timer(struct timer_list *timer);
//删除定时器
int del_tiemr(struct timer_list *timer);
//----------time_t ----------->>>>>>>>struct tm 获取真实的世界时间
struct tm gmtime(time_t *timep)
struct tm localtime(time_t *timep)
//- struct tm ----->>>>> 字符串 time_t---------->字符串
char * asctime(struct tm *tm); char *ctime(time_t *t);
//-------struct tm ---->time_t
mktime(struct tm *tm)
-----------------------------------------------
struct timeval //时间要求较高
struct timezone //时区结构体
struct timeval tv;
if(-1 = gettimeofdate(&tv ,NULL))
{
perror("获取时间错误");
return -1;
}
settimeofdate(&tv,NULL)
/---------------------------------------------------
struct timespec
sleep usleep nanosleep
struct timespec tsp={2,200000},rem; //rem 剩余时间,因为中断打断
nanosleep(&tsp ,&rem);//
while(-1 == nanosleep(&tsp ,&rem)&&(errno==EINTR))
{
tsp = rem;
rem.tv_sec = 0 ;
rem.tv_nsec = 0 ;
}
ctrl + c 是发 sigint 信号
总个五个时间,一个内核时间