获取当前时间
boost::posix_time::ptime currentTime = boost::posix_time::second_clock::local_time();
boost::gregorian::date currentDate = boost::posix_time::second_clock::local_time().date();
boost::posix_time::time_duration newTimeDuration = boost::posix_time::second_clock::local_time().time_of_day();
日期时间段
boost::gregorian::date currentDate = boost::posix_time::second_clock::local_time().date();
boost::gregorian::date_duration newDateDuration = currentDate - boost::gregorian::date( 2000 , 01 , 01 );
时间段
boost::posix_time::ptime previousTime( previewDate , previousTimeDuration );
boost::posix_time::ptime currentTime = boost::posix_time::second_clock::local_time();
boost::posix_time::time_duration timeElapse = currentTime - previousTime;
boost::posix_time::time_duration timeDuration_1 = boost::posix_time::hours( 3 );
boost::posix_time::time_duration timeDuration_2 = boost::posix_time::minutes(3);
boost::posix_time::time_duration timeDuration_3 = boost::posix_time::seconds(3);
boost::posix_time::time_duration timeDuration_4 = boost::posix_time::milliseconds(3);
boost::posix_time::time_duration timeDuration_5 = boost::posix_time::microseconds(3);
//#define BOOST_DATE_TIME_HAS_NANOSECONDS 1
//boost::posix_time::time_duration timeDuration_6 = boost::posix_time::nanoseconds(3);
boost::this_thread::sleep( timeDuration_1 );
时间字符串
string timeString = boost::posix_time::to_iso_string(boost::posix_time::second_clock::local_time());
//timeString = "20170120T121959"
boost::posix_time::time_duration timeDuration = boost::posix_time::duration_from_string("20:43:51");
boost::posix_time::ptime ptime_1 = boost::posix_time::time_from_string("2017-12-09 23:22:09");
boost::posix_time::ptime ptime_2 = boost::posix_time::from_iso_string("20171209T232308");
boost::posix_time::time_duration timeDuration = ptime_2 - ptime_1;
INT32 curHours = timeDuration.hours(); //0
INT32 curMinutes = timeDuration.minutes(); //0
INT32 curSeconds = timeDuration.seconds(); //59
INT64 mmmm = timeDuration.total_milliseconds(); //59000