c++ How to find the time in foreign country taking into account daylight saving?

后端 未结 1 2016
臣服心动
臣服心动 2020-12-14 23:21

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 go

相关标签:
1条回答
  • 2020-12-14 23:48

    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).

    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:

    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 .

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

    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.

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

    0 讨论(0)
提交回复
热议问题