From aa80e4eae1b7790d49bc385fe0d688f8a0a7dce6 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 7 Jul 2017 21:21:57 -0400 Subject: [PATCH] Updated Boost datetime Examples Translated (markdown) --- Boost-datetime-Examples-Translated.md | 41 +++++++++++++-------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/Boost-datetime-Examples-Translated.md b/Boost-datetime-Examples-Translated.md index 7299d79..3a9fba1 100644 --- a/Boost-datetime-Examples-Translated.md +++ b/Boost-datetime-Examples-Translated.md @@ -365,29 +365,26 @@ main() ``` ### Print Hours +```c++ +#include "tz.h" +#include - #include "date.h" - #include "tz.h" - #include - - int - main() - { - using namespace std::chrono; - using namespace date; - // get the current time from the clock -- one second resolution - auto now = floor(current_zone()-> - to_local(system_clock::now())); - // Get the date part out of the time - auto today = floor(now); - auto tomorrow = today + days{1}; // midnight - for (auto i = now; i < tomorrow; i += 1h) - std::cout << i << '\n'; - auto remaining = tomorrow - now; - std::cout << "Time left until midnight: " - << make_time(remaining) << '\n'; - } - +int +main() +{ + using namespace std::chrono; + using namespace date; + // get the current local time from the clock -- one second resolution + auto now = make_zoned(current_zone(), + floor(system_clock::now())).get_local_time(); + // Get the date part out of the time + auto today = floor(now); + auto tomorrow = today + days{1}; // midnight + for (auto i = now; i < tomorrow; i += 1h) + std::cout << i << '\n'; + std::cout << format("Time left until midnight: %T\n", tomorrow - now); +} +``` ### Local to UTC Conversion