#include <iostream>
#include "cctz/civil_time.h"
#include "cctz/time_zone.h"// 时区转换库
// https://github.com/google/cctzint test() {for (cctz::civil_day d(2016, 2, 1); d < cctz::civil_month(2016, 3); ++d) {std::cout << "Hello " << d;if (d.day() == 29) {std::cout << " <- leap day is a " << cctz::get_weekday(d);}std::cout << "\n";}cctz::time_zone nyc;cctz::load_time_zone("America/New_York", &nyc);// Converts the input civil time in NYC to an absolute time.const auto moon_walk =cctz::convert(cctz::civil_second(1969, 7, 20, 22, 56, 0), nyc);std::cout << "Moon walk in NYC: "<< cctz::format("%Y-%m-%d %H:%M:%S %Ez\n", moon_walk, nyc);cctz::time_zone syd;if (!cctz::load_time_zone("Australia/Sydney", &syd)) return -1;std::cout << "Moon walk in SYD: "<< cctz::format("%Y-%m-%d %H:%M:%S %Ez\n", moon_walk, syd);
}
参考
GitHub - google/cctz: CCTZ is a C++ library for translating between absolute and civil times using the rules of a time zone.