现在的位置: 首页 > 综合 > 正文

时间和日期函数

2017年12月19日 ⁄ 综合 ⁄ 共 772字 ⁄ 字号 评论关闭

clock测定运行时间函数

 

  1. #include"stdio.h"  
  2. #include"time.h"  
  3. #include"dos.h"  
  4. #include "Windows.h"  
  5. int main(void)  
  6. {  
  7.     clock_t start,end;  
  8.     start=clock();  
  9.     Sleep(1045);  
  10.     //delay();  
  11.     end=clock();  
  12.     printf("时间是:%-.3f秒\n",(double)(end-start)/CLK_TCK);  
  13.     return 0;  

 

 difftime计算时间差函数

 

  1. #include"time.h"  
  2. #include"stdio.h"  
  3. #include"dos.h"  
  4. #include"conio.h"  
  5. #include"Windows.h"  
  6. void main()  
  7. {  
  8.     time_t first,second;  
  9.     //clrscr();  
  10.     first=time(NULL);  
  11.     Sleep(2000);  
  12.     second=time(NULL);  
  13.     printf("%f 秒\n",difftime(second,first));  

 

 time获取系统时间函数

 

  1. #include"time.h"  
  2. #include"stdio.h"  
  3. void main()  
  4. {  
  5.     time_t t;  
  6.     t=time(&t);  
  7.     printf("从1970年1月1日起到现在经过了%ld秒\n",t);  
  8. printf("现在日期:%s\n",ctime(&t));

 

 

 

本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/735850

抱歉!评论已关闭.