c语言中如何调用获取系统时间

来源:百度知道 编辑:UC知道 时间:2024/05/16 06:44:34

1.用difftime,秒级

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

int main(void)
{
time_t first, second;

first = time(NULL); /* Gets system time */

// 你的程序 ...............

second = time(NULL); /* Gets system time again */

printf("The difference is: %f seconds\n",difftime(second,first));
getch();

return 0;
}

2.用DWORD GetTickCount(VOID)
CTime WINAPI GetCurrentTime( ) throw( );
获得更精确的时间 GetTickCount

3.获取系统编译程序的时间
char* time1 = __DATE__;
char* time2 = __TIME__;
其中__DATE__和__TIME__是俩个宏。