我想通过只保留年、月、日、小时和分钟来boost::posix_time::ptime
从现有的中构建一个新的。ptime
有什么解决办法吗?
编辑:感谢 Rudolfs Bundulis,我找到了一个可行的解决方案:
#include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
using namespace boost::posix_time;
int main()
{
const ptime time(microsec_clock::local_time());
const time_duration time_of_day = time.time_of_day();
const ptime time2(time - microseconds(time_of_day.total_microseconds()) + hours(time_of_day.hours()) + minutes(time_of_day.minutes()));
std::cout << "time 1: " << time << std::endl;
std::cout << "time 2: " << time2 << std::endl;
return 0;
}