温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

库函数调用之时间的显示、计算、应用

发布时间:2020-08-16 16:20:30 来源:网络 阅读:396 作者:TheRoodToDeath 栏目:软件技术

                                                            时间类型
UTC世界时间
日历时间
从1970年1月1日
#include<stdio.h>
struct tm *gmtime(const time_t*timep)
功能;将日历时间转化格林威志时间;
struct tm{

int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year; //tm_year +1900=哪一年
int tm_wday;
int tm_yday;
int tm_isdst;

}
#include<time.h>
#include<stdio.h>
int main(void){
struct tm *local;
time_t t;
t=time(NULL);
local=localtime(&t);
printf("local hour time:%d\n",loccal->tm_hour);
local=gmtime(&t);
printf("utc hour is :%d/n",local->tm_hour);return 0;

}

获取时间
int gettimeofday(struct timeval *tv,struct timezone tz*)
功能;获取从今日凌晨到现在的时差

struct timeval{


int tv_sec; //miao
int tv_usec;//wei miao


};

#include<sys/time.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

 

/************时间函数,延迟函数****************/
void function()
{
 unsigned int i,j;
 double y;
 for(i=0;i<1000;i++)
 for(j=0;j<1000;j++)
 j++;

}

/*******此函数可以计算出一个函数运行的时间********/
main()
{
struct timeval tpstart ,tpend;
float timesuel
gettimeofday(&tpstat,NULL);              // time of start
function();
gettimeofday(&tpend,NULL);              //count time end ;
/*count  time*/

timeuse=1000000*(tpend.tv_sec-tpstart.tv_set);
printf("used time ;\n",timeuse);
exit(0);
}


 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI