c++字符串时间加减

来源:互联网 发布:淘宝hd版分类在哪里 编辑:程序博客网 时间:2024/06/06 06:46
#include <time.h>
#include <iostream>
#include <cstring>
#include <sstream>
using namespace std;


int main()
{
tm tm_;
time_t t_;
char buf[128] = {0};
ostringstream timer;
timer<<"20150216"<<" 23:59:59";
strptime((timer.str()).c_str(), "%Y%m%d %H:%M:%S", &tm_);

t_  = mktime(&tm_);

//变成秒数进行相加减

t_ += 86400;
tm_ = *localtime(&t_);
strftime(buf, 64, "%Y%m%d", &tm_);
return 0;
}
0 0
原创粉丝点击