mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-05 13:44:26 +02:00
Updated Boost datetime Examples Translated (markdown)
@@ -365,29 +365,26 @@ main()
|
||||
```
|
||||
<a name="Print_Hours"></a>
|
||||
### Print Hours
|
||||
```c++
|
||||
#include "tz.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "date.h"
|
||||
#include "tz.h"
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using namespace date;
|
||||
// get the current time from the clock -- one second resolution
|
||||
auto now = floor<seconds>(current_zone()->
|
||||
to_local(system_clock::now()));
|
||||
// Get the date part out of the time
|
||||
auto today = floor<days>(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<seconds>(system_clock::now())).get_local_time();
|
||||
// Get the date part out of the time
|
||||
auto today = floor<days>(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);
|
||||
}
|
||||
```
|
||||
<a name="Local_to_UTC_Conversion"></a>
|
||||
### Local to UTC Conversion
|
||||
|
||||
|
Reference in New Issue
Block a user