提升日期时间转换并增加秒数

Jam*_*mes 4 c++ boost

我需要加载格式为 16/11/2012 11:00:00 的字符串,即 %d/%m/%Y %H:%M ,然后重复添加 900 秒。下面的代码是一个例子,你能帮我让它工作吗?

    #include "stdafx.h"
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <sstream>

#include "boost/date_time/local_time/local_date_time.hpp"

int _tmain(int argc, _TCHAR* argv[])
{
  unsigned int seconds=900;
  using namespace boost::local_time;
  std::stringstream ss;

  // Set up the input datetime format.
  local_time_input_facet *input_facet = new local_time_input_facet("%d/%m/%Y %H:%M");
  ss.imbue(std::locale(ss.getloc(), input_facet));

  local_date_time date(not_a_date_time);
  ss.str("16/11/2012 11:00:00");
  ss >>date;

  local_date_time now=date+seconds;
  std::cout << now << std::endl;
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激,詹姆斯

And*_*hko 7

我现在手上没有提升,请尝试以下操作:

date + boost::posix_time::seconds(900)