1、timer

  不同于系统函数的timer()一般生成一个定时器,boost中的timer是一个计时器,以秒为单位,最小精度为毫秒,使用需要包含头文件"boost\timer.hpp",下面是它的使用方法:

boost--日期处理
    boost::timer t; //对象定义后就开始计时
    cout << "max timespan: " << t.elapsed_max() / 3600 << "h" << endl; //输出最大计时范围,596.523h
    cout << "min timespan: " << t.elapsed_min() << "s" << endl; //输出最小计时范围,0.001s
    cout << "now time elapsed: " << t.elapsed() << "s" << endl; //输出当前计时
View Code

2、date日期类

  data_time库需要编译它来使用,它主要包含date日期类、日期长度类days、weeks、months、years,日期迭代器等。data_time只支持1400-9999年之间的日期,如果创建的日期对象使用了其它的值则会抛出异常,使用需要包含头文件"boost\date_time\gregorian\gregorian.hpp"
  下面是定义date日期类对象的方法:

 

    boost::gregorian::date d; //创建了一个无效的日期对象
    boost::gregorian::date d1(2010, 1, 1);
    boost::gregorian::date d2(2000, boost::date_time::Jan, 1);

    boost::gregorian::date d3 = boost::gregorian::from_string("1999-12-31");
    boost::gregorian::date d4 = boost::gregorian::from_string("1999/12/31");
    boost::gregorian::date d5 = boost::gregorian::from_undelimited_string("19991231");

    boost::gregorian::date d6(2010, 1, 1);
    std::string str = boost::gregorian::to_iso_extended_string(d6); //2010-01-01
    str = boost::gregorian::to_iso_string(d6); //20100101
    str = boost::gregorian::to_simple_string(d6); //2010-Jan-01
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-23
  • 2021-05-29
  • 2021-11-12
  • 2021-11-12
  • 2021-06-17
  • 2021-10-17
猜你喜欢
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
相关资源
相似解决方案