Updated Boost datetime Examples Translated (markdown)

Howard Hinnant
2017-07-07 21:21:57 -04:00
parent b3a44884b7
commit aa80e4eae1

@@ -365,8 +365,7 @@ main()
``` ```
<a name="Print_Hours"></a> <a name="Print_Hours"></a>
### Print Hours ### Print Hours
```c++
#include "date.h"
#include "tz.h" #include "tz.h"
#include <iostream> #include <iostream>
@@ -375,19 +374,17 @@ main()
{ {
using namespace std::chrono; using namespace std::chrono;
using namespace date; using namespace date;
// get the current time from the clock -- one second resolution // get the current local time from the clock -- one second resolution
auto now = floor<seconds>(current_zone()-> auto now = make_zoned(current_zone(),
to_local(system_clock::now())); floor<seconds>(system_clock::now())).get_local_time();
// Get the date part out of the time // Get the date part out of the time
auto today = floor<days>(now); auto today = floor<days>(now);
auto tomorrow = today + days{1}; // midnight auto tomorrow = today + days{1}; // midnight
for (auto i = now; i < tomorrow; i += 1h) for (auto i = now; i < tomorrow; i += 1h)
std::cout << i << '\n'; std::cout << i << '\n';
auto remaining = tomorrow - now; std::cout << format("Time left until midnight: %T\n", tomorrow - now);
std::cout << "Time left until midnight: "
<< make_time(remaining) << '\n';
} }
```
<a name="Local_to_UTC_Conversion"></a> <a name="Local_to_UTC_Conversion"></a>
### Local to UTC Conversion ### Local to UTC Conversion