我想转换一个 boost::posix_time::ptime
到 boost::local_time::local_date_time
使用没有夏令时的时区仅由它与 UTC 的偏移量指定。我正在使用 boost 1.47.0
.
目前我正在尝试创建一个 boost::local_time::custom_time_zone
(又名 custom_time_zone_base<char>
)。该类模板的唯一构造函数如下:
custom_time_zone_base(
const time_zone_names& zone_names,
const time_duration_type& utc_offset,
const dst_adjustment_offsets& dst_shift,
boost::shared_ptr<dst_calc_rule> calc_rule);
我应该提供什么作为 dst_shift
和 calc_rule
争论?或者还有其他更适合我需要的类(class)吗,因为我还提供了 zone_names
作为boost::local_time::time_zone_names
用 4 个空字符串初始化。
最佳答案
日期时间文档中的示例向您展示了如何创建没有 DST 的自定义时区。你可以在http://www.boost.org/doc/libs/1_47_0/doc/html/date_time/examples.html#date_time.examples.simple_time_zone看到它.
查看 phx_1 时区的代码。您基本上传递了一个初始化为 time_duration(0,0,0) 的三个拷贝的 dst_adjustment_offsets(第三个参数),并为计算规则(第四个参数)传递了一个空的共享指针。
(来自示例:)
// create more dependent objects for a non-dst custom_time_zone
time_zone_names tzn2("Mountain Standard Time", "MST", "", ""); // no dst means empty dst strings
time_duration utc_offset2(-7,0,0);
dst_adjustment_offsets adj_offsets2(time_duration(0,0,0),
time_duration(0,0,0),
time_duration(0,0,0));
// no dst means we need a null pointer to the rules
shared_ptr<dst_calc_rule> phx_rules;
// create the custom_time_zones
time_zone_ptr phx_1(new custom_time_zone(tzn2, utc_offset2,
adj_offsets2, phx_rules));
关于c++ - 创建没有夏令时的 boost::local_time::custom_time_zone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7161089/