#include "stdafx.h"
#include <process.h>
#include <iostream>
#include <time.h>
using namespace std;
bool GetCurrTime(char* lpszTime)
{
time_t rt={0};
tm* ptmInfo=NULL;
try
{
time(&rt);
ptmInfo=localtime(&rt);
sprintf(lpszTime,"%d-%d-%d %d:%d:%d",ptmInfo->tm_year+1900,ptmInfo->tm_mon+1,ptmInfo->tm_mday,ptmInfo->tm_hour,ptmInfo->tm_min,ptmInfo->tm_sec);
}
catch (...)
{
return false;
}
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
char szTime[260];
memset(szTime,0,260);
GetCurrTime(szTime);
cout<<szTime<<endl;
system("pause");
return 0;
}
time_t 的使用
最新推荐文章于 2022-10-27 15:35:27 发布