time函数

#include<time.h>

1.time(time_t *)//也可以为NULL

  返回距离UTC时间的秒数

2.gettimeofday()

  可以获得精确的秒和微秒

  struct timeval start,end;

  gettimeofday(&start,NULL);//获取当前时间到start结构体中

  printf("start sec:%ld usec:%ld\n",start.tv_sec,start.tv_usec);//打印秒和微秒

3.localtime()

  根据用户需求,定制化输出时间标志

   struct tm *tm;           time_t tt;
   tm=localtime(&tt);
   printf("%d/%d/%d %d:%d:%d week:%d\n",tm->tm_year+1900,tm->tm_mon+1,tm- >tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tm->tm_wday);

posted @ 2018-04-14 18:30  edan  阅读(251)  评论(0编辑  收藏  举报