首页 > 代码库 > 字符串转日期
字符串转日期
//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;
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;
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。