diff --git a/Examples-and-Recipes.md b/Examples-and-Recipes.md index c3b400e..2903663 100644 --- a/Examples-and-Recipes.md +++ b/Examples-and-Recipes.md @@ -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 + +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. + ### The current time somewhere else (by [Howard Hinnant](https://github.com/HowardHinnant))