C ++如何找到在国外考虑到夏令时间? [英] c++ How to find the time in foreign country taking into account daylight saving?

查看:201
本文介绍了C ++如何找到在国外考虑到夏令时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说,如果是在13:00纽约(美国东部时间),那么它在06:00新西兰(NZST)。
如果新西兰进入夏天的时候,那么当它在13:00纽约(美国东部时间还是),这将是在07:00新西兰(现NZDT)。

Say, if it's 13:00 at new york (EST) , then it's 06:00 at new zealand (NZST). If new zealand goes into summer time, then when it's 13:00 at new york (still EST), it's going to be 07:00 at new zealand (now NZDT).

我读了升压时间库,但在我看来,一个人必须确定夏令时规则自己从本地时间的​​角度找出在国外的时候。

I read the boost time library, but it seems to me one has to determine the daylight saving rules oneself to find out the time in foreign country from the 'localtime' perspective..

例如

 nyc_string = "EST-05:00:00EDT+01:00:00,M4.1.0/02:00:00,M10.5.0/02:00:00";
 // above basically defines the daylight saving rule
 time_zone_ptr nyc_2(new posix_time_zone(nyc_string));

 std::cout << "The second zone is in daylight savings from:\n " 
  << nyc_2->dst_local_start_time(2004) << " through "
  << nyc_2->dst_local_end_time(2004) << std::endl;

来源:<一个href=\"http://www.boost.org/doc/libs/1_39_0/doc/html/date_time/examples.html\">http://www.boost.org/doc/libs/1_39_0/doc/html/date_time/examples.html

也许有些事我还不知道吗?是否提升使用跟踪夏令时规则的任何数据库?我在想,如果有一个很好的方式来调整本地时间在C ++不同的时区,服用夏令规则到account..If我能有一个例子,那简直太伟大了!

Maybe there's something I'm not yet aware of? Does boost use any database that keeps track of daylight saving rules? I wonder if there's a nice way to adjust local time to different time zone in c++, taking the daylight saving rules into account..If I could have an example, that'd be so great!

推荐答案

Boost.DateTime具有 date_time_zon​​espec.csv 评为区数据库位于库/ DATE_TIME /数据。在<一个href=\"http://www.boost.org/doc/libs/1_48_0/doc/html/date_time/examples.html#date_time.examples.flight\"相对=nofollow>飞行时间实例文档中显示了如何访问和使用它。该数据库不包含的时区变化的历史。此外,还似乎没有被托管的更新这个数据库(超过Boost库本身以外)的地方。

Boost.DateTime has a timezone database named date_time_zonespec.csv located in libs/date_time/data. The Flight Time Example in the documentation shows how to access and use it. This database doesn't contain the history of timezone changes. There also doesn't seem to be a place hosting updates to this database (other than the Boost library itself).

如果你需要准确,最新,时区数据,然后查看 ICU时区类流行 ICU 国际图书馆从IBM的。正如更新时区数据部分:

If you need accurate, up-to-date, time zone data, then check out the ICU Time Zone Classes of the popular ICU internationalization library from IBM. As mentioned in the Updating the Time Zone Data section:

在ICU时区数据从行业标准的TZ产生
  使用TZ code数据库
  (
http://source.icu -project.org/repos/icu/icu/trunk/source/tool​​s/tz$c$c/
  )工具。
  最近的时区数据ICU数据文件可以从下载
  更新URL,
   http://source.icu-project.org/repos/icu /数据/主干/的tzdata / icunew

The time zone data in ICU is generated from the industry-standard TZ database using the tzcode (http://source.icu-project.org/repos/icu/icu/trunk/source/tools/tzcode/ ) tool. The ICU data files with recent time zone data can be downloaded from the update URL, http://source.icu-project.org/repos/icu/data/trunk/tzdata/icunew .

在ICU时区数据库从现在的 TZ数据库导出= http://en.wikipedia.org/wiki/ICANN相对=nofollow> ICANN

The ICU timezone database is derived from the tz database now maintained by ICANN.

要通过HTTP下载文件在C ++程序,你可以使用的libcurl 或的 cURLpp C ++包装。这可能是更容易设置调度操作系统上定期下载最新的数据库。

To download a file via http in a C++ program, you can use libcurl or the cURLpp C++ wrapper. It might be easier to setup a scheduler on your OS to regularly download the latest database.

由于在评论中已经mentionned,使用UTC的始终作为存储和业务逻辑。只有转换到/自本地时间显示/输入的目的。

As already mentionned in the comments, use UTC consistently for storage and business logic. Only convert to/from local times for display/input purposes.

这篇关于C ++如何找到在国外考虑到夏令时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆