您的位置:首页 > 其它

以字符串形式返回当前系统时间,默认格式为“年月日时分秒”

2006-05-11 14:46 495 查看
以字符串形式返回当前系统时间,默认格式为“年月日时分秒”

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐