c++ 两个字符串加减得到相差秒数

来源:互联网 发布:com和cn域名哪个好 编辑:程序博客网 时间:2024/05/17 07:04
/*
@endTime 格式:2016-02-23 00:00:00
@startTime 格式:2016-02-23 00:00:00
*/
double calculateTime(const std::string& endTime, const std::string& startTime)
{
tm tm_s;
time_t start;
strptime(startTime.c_str(), "%Y-%m-%d %H:%M:%S", &tm_s);
start = mktime(&tm_s);
tm tm_e;
time_t end;
strptime(endTime.c_str(), "%Y-%m-%d %H:%M:%S", &tm_e);
end = mktime(&tm_e);
double result = std::difftime(end, start);
return result;
}
0 0
原创粉丝点击