c++, boost ptime 날짜 계산

boost::posix_time::ptime t1;
boost::posix_time::ptime t2;

t1 = boost::posix_time::time_from_string("2018-08-20 23:59:59.000");
t2 = boost::posix_time::from_iso_string("20180821T010101");

int day_diff = (t2.date() - t1.date()).days();

// 2018년 8월 20일 23시 59분 59초와 2018년 8월 21일 01시 01분 01초 사이의 날짜 차이는 1일이다.
// day_diff에 들어있는 결과는 1

댓글

이 블로그의 인기 게시물

윈도우 작업 스케줄러 이용한 프로그램 실행이 안될 때

우분투 방화벽(ufw)으로 IP 접근 차단 및 특정 IP 접근 허용

우분투(ubuntu) kernel 업그레이드 시 boot 용량 부족, 의존성 문제