boost库获取时间方法:

boost::gregorian::date td(boost::gregorian::day_clock::local_day()); //获取年月日

auto tt = boost::posix_time::second_clock::local_time().time_of_day(); //获取时分秒

boost::posix_time::ptime  now = boost::posix_time::microsec_clock::local_time();
    

const boost::posix_time::time_duration ssss = now.time_of_day(); //获取毫秒

char szLine[2048];

 

sprintf(szLine, "%04d-%02d-%02d %02d:%02d:%02d:%03d", td.year(), td.month(), td.day().as_number(), tt.hours(), tt.minutes(), tt.seconds(), ssss.total_microseconds() % 1000);

你可能感兴趣的:(boost)