boost location-dependent times

Posted sssblog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 ptdate2014, 5, 12, time_duration12, 0, 0;
  local_date_time dtpt, 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的主要内容,如果未能解决你的问题,请参考以下文章

Boost.Thread 链接 - boost_thread 与 boost_thread-mt

Boost 和 Boost.Build 的设置

阿迪bounce和boost哪个走路舒服 bounce和boost对比

如何移植boost库到Android

大家怎么处理QT库和stl,boost等的关系

boost--BOOST_AUTOtypeofresult_of