码迷,mamicode.com
首页 > 其他好文 > 详细

字符串转日期

时间:2014-05-14 21:52:15      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:c语言   c++   字符串日期   

//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

字符串转日期

标签:c语言   c++   字符串日期   

原文地址:http://blog.csdn.net/ctxbloger/article/details/25816631

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!