timer

localtime.c

#include<stdio.h>
#include<time.h>
main()
{
 time_t temp;
 struct tm* p;
 time(&temp);
 p = localtime(&temp);
 printf("year %d\n",p->tm_year+1900);
 printf("month %d\n",p->tm_mon+1);
 printf("day %d\n",p->tm_mday);
 printf("hour %d\n",p->tm_hour);
 printf("minute %d\n",p->tm_min);
 printf("second %d\n",p->tm_sec);
 printf("weekday %d\n",p->tm_wday);
}

 

time.c

#include<stdio.h>
#include<time.h>

int main()
{
 time_t s;
 s=time((time_t*)NULL);
 printf("now %ld",s);
 return 0;
}

 

gettime.c

#include<stdio.h>
#include<time.h>
main()
{
 time_t temp;
 struct tm* p;
 time(&temp);
 p = gmtime(&temp);
 printf("year %d\n",p->tm_year+1900);
 printf("month %d\n",p->tm_mon+1);
 printf("day %d\n",p->tm_mday);
 printf("hour %d\n",p->tm_hour);
 printf("minute %d\n",p->tm_min);
 printf("second %d\n",p->tm_sec);
 printf("weekday %d\n",p->tm_wday);
}

 

ctime.c

#include<stdio.h>
#include<time.h>

int main()
{
 time_t temp;
 char *ti;
 time(&temp);
 ti=ctime(&temp);
 printf("%s\n",ti);
 return 0;
}

 

mktime.c

#include<stdio.h>
#include<time.h>

int main()
{
 time_t temp1,temp2;
 char *ti1, *ti2;
 struct tm *p;
 time(&temp1);
 ti1=ctime(&temp1);
 printf("%s\n",ti1);
 
 
 p=gmtime(&temp1);
 temp2=mktime(p);
 ti2 = ctime(&temp2);
 printf("%s\n",ti2);
 return 0;
}

 

runtime.c

#include<stdio.h>
#include<time.h>
#include<sys/time.h>
#include<unistd.h>
int main()
{
 struct timeval tv1,tv2;
 struct timezone tz1,tz2;
 long sec,usec,i;

 gettimeofday(&tv1,&tz1);
 for(i=1;i<1000;i++)
 gettimeofday(&tv2,&tz2);
 sec = tv2.tv_sec-tv1.tv_sec;
 usec = tv2.tv_usec-tv1.tv_usec;
 printf("%ld \n",1000000*sec+usec);
 return 0;
}

inbetweenout.c

#include<stdio.h>
#include<time.h>
#include<sys/time.h>
#include<unistd.h>
int main()
{
 struct timeval tv1,tv2;
 struct timezone tz1,tz2;
 int sec;
        long usec,i;

 gettimeofday(&tv1,&tz1);
 printf("please input a int number\n");
 scanf("%ld",&i); 
 gettimeofday(&tv2,&tz2);
 sec = tv2.tv_sec-tv1.tv_sec;
 usec = tv2.tv_usec-tv1.tv_usec;
 printf("%d\n",sec);
 printf("%ld \n",usec);
 return 0;
}

 

asctime.c

#include<stdio.h>
#include<time.h>

int main()
{
 time_t temp;
 struct tm * p;
 char *ti;
 time(&temp);
 p=gmtime(&temp);
 ti=asctime(p);
 printf("%s\n",ti);
 return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值