问题
How to subtract 30 days from a current Date in c++ using poco library ?
回答1:
First approach is to substract to the date a new DateTime constructed like this:
Poco::DateTime(0, 0, 30);
But it is not allowed at runtime because month must be greater than 1. The solution is to use a Timespan:
Poco::DateTime date = Poco::DateTime();
std::cout << Poco::DateTimeFormatter::format(date, Poco::DateTimeFormat::ASCTIME_FORMAT) << std::endl;
date = Poco::DateTime(date.timestamp() - Poco::Timespan(30 * 24 * 60 * 60, 0)); // 30 days in seconds;
std::cout << Poco::DateTimeFormatter::format(date, Poco::DateTimeFormat::ASCTIME_FORMAT) << std::endl;
This is the output of this code snippet:
Fri Sep 18 08:18:21 2020
Wed Aug 19 08:18:21 2020
来源:https://stackoverflow.com/questions/63940303/how-to-subtract-30-days-from-a-current-date-in-c-using-poco-library