码迷,mamicode.com
首页 > 其他好文 > 详细

boost location-dependent times

时间:2019-08-05 19:09:28      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:res   bool   std   pen   alc   dna   cti   share   contains   

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.

boost location-dependent times

标签:res   bool   std   pen   alc   dna   cti   share   contains   

原文地址:https://www.cnblogs.com/sssblog/p/11304709.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!