time_t 的使用

#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)