4
我需要能够在C++中转换和比较日期。我发现Boost库非常适合我的需要,但我不能让它正常工作:比较日期C++(使用boost)
// include headers...
using namespace boost::posix_time;
using namespace boost::gregorian;
ptime p1(second_clock::universal_time());
p1 -= weeks(5); // Subtract 5 weeks from p1 using boost...
std::string old_date("2011-11-19"); // format:YYYY-MM-DD
std:stringstream ss(old_date);
ptime p2;
p2 << ss;
if(p1 <= p2){
// this should not happen in this case (yet it does!) p1 > p2!!
}
基本上我希望能够减去周(或月)当地日期,然后比较以YYYY-MM-DD格式的字符串形式给出日期...
明白了现在的工作。谢谢您的帮助! – user1432032 2012-08-04 03:41:37