• boost location-dependent times


    1. local_date_time

    #include <boost/date_time/local_time/local_time.hpp>
    #include <iostream>
    
    using namespace boost::local_time;
    using namespace boost::posix_time;
    using namespace boost::gregorian;
    
    int main()
    {
      time_zone_ptr tz(new posix_time_zone( "CET+1"));
      ptime pt{date{2014, 5, 12}, time_duration{12, 0, 0}};
      local_date_time dt{pt, tz};
      std::cout << dt.utc_time() << std::endl;
      std::cout << dt << std::endl;
      std::cout << dt.local_time() << std::endl;
      std::cout << dt.zone_name() << std::endl;
      return 0;
    }

    The constructor of boost::local_time::local_date_time expects its first parameter to be an object of type boost::posix_time::ptime and its second parameter to be an object of type boost::local_time::time_zone_ptr. boost::local_time::time_zone_ptr is a type of definition for boost::shared_ptr<boost::local_time::time_zone>. The type definition is based on boost::local_time::time_zone, not boost::local_time::posix_time_zone.

    Values used to initialize objects of type boost::posix_time::ptime and boost::local_time::local_date_time always relate to the UTC time zone by default.

    When an object of type boost::local_time::local_date_time is written to the standard output stream or a call to the member function local_time() is made, the deviation in hours is used to calculate the local time.

    2. local_time_period

    #include <boost/date_time/local_time/local_time.hpp>
    #include <iostream>
    
    using namespace boost::local_time;
    using namespace boost::posix_time;
    using namespace boost::gregorian;
    
    int main()
    {
      time_zone_ptr tz(new posix_time_zone("CET+0"));
    
      ptime pt1(date(2014, 12, 5), time_duration(12, 0, 0));
      local_date_time dt1(pt1, tz);
    
      ptime pt2(date(2014, 12, 5), time_duration(18, 0, 0));
      local_date_time dt2(pt2, tz);
    
      local_time_period tp(dt1, dt2);
    
      std::cout.setf(std::ios::boolalpha);
      std::cout << tp.contains(dt1) << std::endl;
      std::cout << tp.contains(dt2) << std::endl;
      return 0;
    }

    The constructor of boost::local_time::local_time_period in example above expects two parameters of type boost::local_time::local_date_time. As with other types provided for periods, the second parameter, which represents the end time, is not part of the period.

  • 相关阅读:
    ECC 构筑安全可靠的区块链
    代理模式和装饰者模式
    Context都没弄明白,还怎么做Android开发?
    如何在Android Studio中查看一个类的继承关系呢?
    Android控件的继承关系
    安卓控件体系结构
    Android View框架总结(三)View工作原理
    Laravel中用GuzzleHttp
    学习PHP好,还是Python好呢?
    ElasticSearch入门 第一篇:Windows下安装ElasticSearch
  • 原文地址:https://www.cnblogs.com/sssblog/p/11304709.html
Copyright © 2020-2023  润新知