boost::posix_time 이용한 날짜, 시간처리
void TimeZero()
{
boost::posix_time::ptime epoch( boost::gregorian::date(1970,1,1),
boost::posix_time::time_duration(0,0,0));
boost::posix_time::ptime now = boost::posix_time::second_clock::universal_time();
boost::posix_time::time_duration diff = now - epoch;
diff.total_seconds(); //유닉스 time_t 출력
time(0); //유닉스 time_t 출력
}
void LocalTime()
{
boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
boost::gregorian::date d = now.date(); //Extract Date
boost::posix_time::time_duration t = now.time_of_day(); //Extract Time
d.year(); d.month(); d.day(); d.hours(); d.minutes(); d.seconds();
struct tm T = boost::posix_time::to_tm(now); // ptime을 struct tm으로 변환
T.tm_year+1900; T.tm_mon; T.tm_mday; T.tm_hour; T.tm_min; T.tm_sec;
time_t tNow = time(0);
LocalTime(&T, &tNow);
T.tm_year+1900; T.tm_mon; T.tm_mday; T.tm_hour; T.tm_min; T.tm_sec;
}
void TimeConvert()
{
boost::posix_time::ptime t;
time_t tNow = time(0);
t = boost::posix_time::time_from_string("2016-10-17 09:16:00"); //문자열을 ptime으로 변환
t = boost::posix_time::from_iso_string("20161017T091600"); //문자열을 ptime으로 변환
t = boost::posix_time::from_time_t(tNow);
}
void TimePlus()
{
boost::posix_time::ptime t = boost::posix_time::second_clock::local_time();
t = t + boost::gregorian::years(1); // 현재 시간 + 1년
t = t + boost::gregorian::months(1); // 현재 시간 + 1달
t = t + boost::gregorian::days(1); // 현재 시간 + 1일
t = t + boost::posix_time::hours(1); // 현재 시간 + 1시간
t = t + boost::posix_time::minutes(1); // 현재 시간 + 1분
t = t + boost::posix_time::seconds(1); // 현재 시간 + 1초
}