AKever

导航

C\C++ 打印系统时间

C\C++ 打印系统时间

include<time.h>

time_t t = time(0); //time_t(长整形)
char tmp[64];
strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A 本年第%j天 %z",localtime(&t) );
printf("time: %ld\n", t);
printf("time: %s \n", tmp);

 Linux 

#include <stdio.h>  
#include <sys/time.h>    
long getCurrentTime()  
{  
   struct timeval tv;  
   gettimeofday(&tv,NULL);  
   return tv.tv_sec * 1000 + tv.tv_usec / 1000;  
}  
  int main()  
{  
    printf("c/c++ program:%ld\n",getCurrentTime());  
    return 0;  
}

 

windows

#include "windows.h"

//获取程序运行时间(毫秒)
long curTime = GetTickCount();//程序段开始前取得系统运行时间(ms)

 

posted on 2014-07-04 12:52  AKever  阅读(1179)  评论(0)    收藏  举报