년에서 새 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;
}
감사합니다! 솔루션은 milli/microseconds가 아니라 초를 올바르게 삭제합니다. 나는 당신의 해결책을 채택했다. #INCLUDE 사용법 #include <높일 \ DATE_TIME \ posix_time \ posix_time.hpp> 네임 스페이스 부스트를 사용하여 : posix_time을; int main() { ptime time (microsec_clock :: local_time()); \t time_duration time_of_day = time.time_of_day(); \t ptime time2 (시간 - 마이크로 초 (time_of_day.total_microseconds()) + 시간 (time_of_day.hours()) + 분 (time_of_day.minutes())); } return 0; } –
Alfred
젠장, 내가 옳다는 것에 너무 가까웠다 - 나는 초 부분이 우물 아래의 모든 파티션을 가지고 있다고 생각했다. 어쩌면 적어도 투표 할 자격이있다. D –
물론 하하하 : p – Alfred