以字符串形式返回当前系统时间,默认格式为“年月日时分秒”
#include <ctime>
#include <string>
using namespace std;
class CCurrentTime
{
private:
time_t m_tDate;
string m_strCurrentTime;
int m_strSize;
public:
CCurrentTime();
~CCurrentTime();
string GetCurrentTime( char *format = "%Y%m%d%H%M%S" );
};
CCurrentTime::CCurrentTime()
{
time( &this->m_tDate );
this->m_strSize = 255;
this->m_strCurrentTime.resize( this->m_strSize );
}
CCurrentTime::~CCurrentTime()
{
}
string CCurrentTime::GetCurrentTime( char *format )
{
char *stemp = new char[this->m_strSize];
strftime(
stemp ,
this->m_strSize ,
format ,
gmtime( &this->m_tDate )
);
this->m_strCurrentTime = stemp;
delete[]stemp;
return this->m_strCurrentTime;
}