I have a boost::posix_time::ptime
that points to March 31st 2010
like this:
ptime p(date(2010, Mar, 31));
开发者_StackOverflow中文版I would like to subtract a month (and possibly years) from this date. From the docs I see these two operators: ptime operator-(time_duration)
and ptime operator-(days)
but none of them can work with months/years. If I try and do:
time_duration duration = hours(24 * 30);
ptime pp = p - duration;
I'm getting March 1st and if I'm trying:
ptime pp = p - days(30);
I'm still getting March 1st, while I'd like to get February 28th.
How can I achieve my desired result? (I would like to get the desired result also when subtracting a month from March 28, 29, 30)boost::posix_time::ptime::date() operator returns date object. You can call greg_year, greg_month etc. for this object.
Well, I guess you already know that not all months have 30 days so you can't subtract with 30 days in general.
You should ask yourself what you mean by "subtract a month".
精彩评论