Updated Boost datetime Examples Translated (markdown)

Howard Hinnant
2017-07-07 21:38:58 -04:00
parent ff4852e301
commit 9f99dcc68a

@@ -520,36 +520,34 @@ main()
``` ```
<a name="Seconds_Since_Epoch"></a> <a name="Seconds_Since_Epoch"></a>
### Seconds Since Epoch ### Seconds Since Epoch
```c++
#include "tz.h"
#include <iostream>
#include "date.h" int
#include "tz.h" main()
#include <iostream> {
using namespace std::chrono;
using namespace date;
int auto nyc_time = make_zoned("America/New_York",
main() local_days(2004_y/oct/4) + 12h + 14min + 32s);
{ std::cout << nyc_time << '\n';
using namespace std::chrono; auto sys_epoch = sys_days{};
using namespace date; std::cout << sys_epoch << '\n';
auto nyc_time = make_zoned("America/New_York", // first convert nyc_time to utc via the get_sys_time()
local_days(2004_y/oct/4) + 12h + 14min + 32s); // call and subtract the sys_epoch.
std::cout << nyc_time << '\n'; auto sys_time = nyc_time.get_sys_time();
auto time_t_epoch = sys_days(1970_y/1/1);
std::cout << time_t_epoch << '\n';
// first convert nyc_time to utc via the get_sys_time() // Expected 1096906472
// call and subtract the time_t_epoch. std::cout << "Seconds diff: " << sys_time - sys_epoch << '\n';
auto sys_time = nyc_time.get_sys_time();
auto diff = nyc_time.get_sys_time() - time_t_epoch;
// Expected 1096906472 // Take leap seconds into account
std::cout << "Seconds diff: " << diff.count() << '\n'; auto utc_time = to_utc_time(sys_time);
auto utc_epoc = to_utc_time(sys_epoch);
// Take leap seconds into account // Expected 1096906494, an extra 22s
auto utc_time = utc_clock::sys_to_utc(sys_time); std::cout << "Seconds diff: " << utc_time - utc_epoc << '\n';
auto utc_epoc = utc_clock::sys_to_utc(time_t_epoch); }
diff = utc_time - utc_epoc; ```
// Expected 1096906494, an extra 22s
std::cout << "Seconds diff: " << diff.count() << '\n';
}