mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-04 13:14:26 +02:00
Updated Examples and Recipes (markdown)
@@ -58,12 +58,33 @@ main()
|
||||
|
||||
`system_clock::now()` of course gets the current time. It is a de facto standard that this current time is measured in terms of [Unix Time](https://en.wikipedia.org/wiki/Unix_time) which is a very close approximation to UTC. `zoned_time` pairs the current UTC time with the computer's current local time zone. The `zoned_time` has a streaming operator so you can easily print it out:
|
||||
|
||||
```c++
|
||||
```
|
||||
2016-07-05 23:01:05.818378 EDT
|
||||
```
|
||||
|
||||
Note that the precision of this output is with whatever precision your `system_clock::now()` supports (microseconds on macOS where I'm writing this).
|
||||
|
||||
If you don't want the timezone abbreviation printed out, another option is to call the member function `to_local` on `time_zone` itself:
|
||||
|
||||
```c++
|
||||
#include "date/tz.h"
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using date::operator<<;
|
||||
std::cout << date::current_zone()->
|
||||
to_local(std::chrono::system_clock::now()) << '\n';
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
2016-07-05 23:01:05.818378
|
||||
```
|
||||
|
||||
The `using date::operator<<;` is necessary because the result of `to_local` is a `std::chrono::time_point` and ADL won't find it's streaming operator in `namespace date` without a little help.
|
||||
|
||||
<a name="elsetime"></a>
|
||||
### The current time somewhere else
|
||||
(by [Howard Hinnant](https://github.com/HowardHinnant))
|
||||
|
Reference in New Issue
Block a user