您的位置:首页 > 编程语言 > C语言/C++

【C++】获取系统时间

2013-10-11 16:27 253 查看
DateTimeData::DateTimeData()
{
m_strDate = "";
m_longDate = 0l;
time_t t = time(0);
char temp[64];
m_longDate = t;
strftime(temp, sizeof(temp), "%Y-%m-%d %H:%M:%S", localtime(&t));
m_strDate = temp;
}

DateTimeData::DateTimeData(string strDate)
{
if (strDate == "" || strDate.length() != 19) {
m_longDate = 0l;
m_strDate = "";
return;
}

m_strDate = strDate;

tm t;
t.tm_year = atoi(m_strDate.substr(0,4).c_str());
t.tm_mon = atoi(m_strDate.substr(5,7).c_str()) - 1;
t.tm_mday = atoi(m_strDate.substr(8,10).c_str());
t.tm_hour = atoi(m_strDate.substr(11,13).c_str());
t.tm_min = atoi(m_strDate.substr(14,16).c_str());
t.tm_sec = atoi(m_strDate.substr(17,19).c_str());
t.tm_isdst = 0;

time_t t_ = mktime(&t);
m_longDate = t_;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  获取系统时间