From 0541e58c2b3266980c897a8c42b5802da0350cf5 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Thu, 22 Apr 2021 14:13:37 -0400 Subject: [PATCH] Updated Examples and Recipes (markdown) --- Examples-and-Recipes.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Examples-and-Recipes.md b/Examples-and-Recipes.md index 2903663..64e5b91 100644 --- a/Examples-and-Recipes.md +++ b/Examples-and-Recipes.md @@ -105,12 +105,33 @@ main() This outputs the current time in Shanghai, for example: -```c++ +``` 2016-07-06 11:01:05.818378 CST ``` All IANA timezone names (or links -- aliases to timezones) are supported. +Like with the current local time, if you just want a local `time_point` (without the timezone abbreviation), you can work directly with the `time_zone` if desired: + +```c++ +#include "date/tz.h" +#include + +int +main() +{ + using date::operator<<; + std::cout << date::locate_zone("Asia/Shanghai")-> + to_local(std::chrono::system_clock::now()) << '\n'; +} +``` + +``` +2016-07-06 11:01:05.818378 +``` + +If `locate_zone()` can't find the `time_zone`, it will throw a `std::runtime_error` with a helpful `what()` message. + ### Get the current difference between any two arbitrary time zones (by [Howard Hinnant](https://github.com/HowardHinnant))