我认为发现 IANA timezones 目前使用缩写“GMT”会很有趣,无论是现在还是从现在起 6 个月后(以赶上那些目前处于夏令时的人)。
使用这个free, open source C++11/14 library,我编写了这个程序:
#include "tz.h"
#include <string>
#include <iostream>
#include <vector>
template <class Duration>
std::vector<date::zoned_time<std::common_type_t<Duration, std::chrono::seconds>>>
find_by_abbrev(date::sys_time<Duration> tp, const std::string& abbrev)
{
using namespace std::chrono;
using namespace date;
std::vector<zoned_time<std::common_type_t<Duration, seconds>>> results;
auto& db = get_tzdb();
for (auto& z : db.zones)
{
if (z.get_info(tp).abbrev == abbrev)
results.push_back(make_zoned(&z, tp));
}
return results;
}
int
main()
{
using namespace std::chrono;
using namespace date;
auto now = system_clock::now();
auto v = find_by_abbrev(now, "GMT");
for (auto const& x : v)
std::cout << format("%F %H:%M:%S %Z %z", x) << " "
<< x.get_time_zone()->name() << '\n';
std::cout << '\n';
v = find_by_abbrev(now + months{6}, "GMT");
for (auto const& x : v)
std::cout << format("%F %H:%M:%S %Z %z", x) << " "
<< x.get_time_zone()->name() << '\n';
}
这会在地球上搜索当前使用“GMT”的所有时区,包括现在和 6 个月后,并将它们打印出来:
2016-06-18 01:00:25.632773 GMT +0000 Africa/Abidjan
2016-06-18 01:00:25.632773 GMT +0000 Africa/Accra
2016-06-18 01:00:25.632773 GMT +0000 Africa/Bissau
2016-06-18 01:00:25.632773 GMT +0000 Africa/Monrovia
2016-06-18 01:00:25.632773 GMT +0000 America/Danmarkshavn
2016-06-18 01:00:25.632773 GMT +0000 Atlantic/Reykjavik
2016-06-18 01:00:25.632773 GMT +0000 Etc/GMT
2016-12-17 15:55:01.632773 GMT +0000 Africa/Abidjan
2016-12-17 15:55:01.632773 GMT +0000 Africa/Accra
2016-12-17 15:55:01.632773 GMT +0000 Africa/Bissau
2016-12-17 15:55:01.632773 GMT +0000 Africa/Monrovia
2016-12-17 15:55:01.632773 GMT +0000 America/Danmarkshavn
2016-12-17 15:55:01.632773 GMT +0000 Atlantic/Reykjavik
2016-12-17 15:55:01.632773 GMT +0000 Etc/GMT
2016-12-17 15:55:01.632773 GMT +0000 Europe/Dublin
2016-12-17 15:55:01.632773 GMT +0000 Europe/London
我很高兴看到在所有情况下 UTC 偏移量都是+0000。你永远不知道政治家和时区。一些立法机构可以很容易地宣布“绿山时间”(明天就可能)。