添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
  • std::string strTime = boost::gregorian::to_iso_string(\
  • boost::gregorian::day_clock::local_day());
  • std::cout << strTime.c_str() << std::endl;
  • std::string strTime = boost::gregorian::to_iso_string(\
  • boost::gregorian::day_clock::local_day());
  • std::cout << strTime.c_str() << std::endl;

  • 2. 输出YYYYMMDD-HH:MM:SS
  • std::string strTime = boost::posix_time::to_iso_string(\
  • boost::posix_time::second_clock::local_time());
  • // 这时候strTime里存放时间的格式是YYYYMMDDTHHMMSS,日期和时间用大写字母T隔开了
  • int pos = strTime.find( 'T');
  • strTime.replace(pos,1,std::string( "-"));
  • strTime.replace(pos + 3,0,std::string( ":"));
  • strTime.replace(pos + 6,0,std::string( ":"));
  • std::cout << strTime.c_str() << std::endl;
  • std::string strTime = boost::posix_time::to_iso_string(\
  • boost::posix_time::second_clock::local_time());
  • // 这时候strTime里存放时间的格式是YYYYMMDDTHHMMSS,日期和时间用大写字母T隔开了
  • int pos = strTime.find( 'T');
  • strTime.replace(pos,1,std::string( "-"));
  • strTime.replace(pos + 3,0,std::string( ":"));
  • strTime.replace(pos + 6,0,std::string( ":"));
  • std::cout << strTime.c_str() << std::endl;
    1. #include <boost/date_time/posix_time/posix_time.hpp>
    2. #include <boost/thread.hpp>
    3. #define BOOST_DATE_TIME_SOURCE
    4. boost::posix_time::ptime time_now,time_now1;
    5. boost::posix_time::millisec_posix_time_system_config::time_duration_type time_elapse;
    6. // 这里为微秒为单位;这里可以将microsec_clock替换成second_clock以秒为单位;
    7. time_now = boost::posix_time::microsec_clock::universal_time();
    8. // sleep 100毫秒;
    9. boost::this_thread::sleep(boost::posix_time::millisec(100));
    10. time_now1 = boost::posix_time::microsec_clock::universal_time();
    11. time_elapse = time_now1 - time_now;
    12. // 类似GetTickCount,只是这边得到的是2个时间的ticket值的差,以微秒为单位;
    13. int ticks = time_elapse.ticks();
    14. // 得到两个时间间隔的秒数;
    15. int sec = time_elapse.total_seconds();
      1. #include <boost/date_time/posix_time/posix_time.hpp>
      2. #include <boost/thread.hpp>
      3. #define BOOST_DATE_TIME_SOURCE
      4. boost::posix_time::ptime time_now,time_now1;
      5. boost::posix_time::millisec_posix_time_system_config::time_duration_type time_elapse;
      6. // 这里为微秒为单位;这里可以将microsec_clock替换成second_clock以秒为单位;
      7. time_now = boost::posix_time::microsec_clock::universal_time();
      8. // sleep 100毫秒;
      9. boost::this_thread::sleep(boost::posix_time::millisec(100));
      10. time_now1 = boost::posix_time::microsec_clock::universal_time();
      11. time_elapse = time_now1 - time_now;
      12. // 类似GetTickCount,只是这边得到的是2个时间的ticket值的差,以微秒为单位;
      13. int ticks = time_elapse.ticks();
      14. // 得到两个时间间隔的秒