//******************************************************** // The following code example is taken from the book // C++20 - The Complete Guide // by Nicolai M. Josuttis (www.josuttis.com) // http://www.cppstd20.com // // The code is licensed under a // Creative Commons Attribution 4.0 International License // http://creativecommons.org/licenses/by/4.0/ //******************************************************** #include #include #include int main() { namespace chr = std::chrono; // initialize a utc_time<> with a leap second: chr::utc_time tp; std::istringstream{"2015-6-30 23:59:60"} >> chr::parse(std::string{"%F %T"}, tp); // convert it to other clocks and print that out: auto tpUtc = chr::clock_cast(tp); std::cout << "utc_time: " << std::format("{:%F %T %Z}", tpUtc) << '\n'; auto tpSys = chr::clock_cast(tp); std::cout << "sys_time: " << std::format("{:%F %T %Z}", tpSys) << '\n'; auto tpGps = chr::clock_cast(tp); std::cout << "gps_time: " << std::format("{:%F %T %Z}", tpGps) << '\n'; auto tpTai = chr::clock_cast(tp); std::cout << "tai_time: " << std::format("{:%F %T %Z}", tpTai) << '\n'; auto tpFile = chr::clock_cast(tp); std::cout << "file_time: " << std::format("{:%F %T %Z}", tpFile) << '\n'; }