zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    pm2中文文档
    大前端技能图谱
    手把手教你用express搭建个人博客(二)
    javascript this讲解
    手把手教你用express搭建个人博客(一)
    使用国内手机号注册Google帐号的方法(2020-12-13亲测有效)
    常见浏览器修改User-Agent的方法
    Debian 9 Stretch国内常用镜像源
    Nginx核心模块内置变量
    tmux基本操作
  • 原文地址:https://www.cnblogs.com/sssblog/p/11304709.html
Copyright © 2011-2022 走看看