获取当前时间的函数

 

#include "stdafx.h"

#include

#include

#include

//#include

 

bool GetCurTime(char* curtime)

{

time_t t;

char szChar[50]={0};

t = time(0);

struct tm *ptm = localtime(&t);

sprintf(szChar,"%4d/%02d/%02d %02d:%02d:%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);

strcpy(curtime,szChar);

return true;

 

}

int _tmain(int argc, _TCHAR* argv[])

{

char chTime[50];

GetCurTime(chTime);

printf("%s",chTime);

gets(chTime);

return 0;

}

 

你可能感兴趣的:(获取当前时间的函数)