字符串转日期

时间:2014-05-14 21:52:15   收藏:0   阅读:248
//Processing date
    struct tm time;
std::string date;
char dateBuff[128] = {0};
time.tm_year = atoi(md_date.getString().substr(0,4).c_str()) - 1900;
time.tm_mon =  atoi(md_date.getString().substr(4,2).c_str()) - 1;
time.tm_mday = atoi(md_date.getString().substr(6,2).c_str()) ;
time.tm_hour = atoi(md_time.getString().substr(0,2).c_str()) ;
time.tm_min =  atoi(md_time.getString().substr(3,2).c_str());
time.tm_sec =  atoi(md_time.getString().substr(6,2).c_str());
std::string mmin =  md_time.getString().substr(9,3);
time_t secs = mktime(&time);
secs += 8*60*60;
struct tm *md_localtime = localtime(&secs);
sprintf(dateBuff, "%02d%02d%02d%02d%02d", md_localtime->tm_mon+1, md_localtime->tm_mday, md_localtime->tm_hour, md_localtime->tm_min, md_localtime->tm_sec);
dateStream << md_localtime->tm_year+1900 << dateBuff << mmin ;
dateStream >> date;

字符串转日期,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!