diff --git a/Examples-and-Recipes.md b/Examples-and-Recipes.md index 20f3f4b..efd3c9f 100644 --- a/Examples-and-Recipes.md +++ b/Examples-and-Recipes.md @@ -2,14 +2,34 @@ - [Obtaining a `time_point` from `y/m/d h:m:s` components](#time_point_to_components) - [Obtaining `y/m/d h:m:s` components from a `time_point`](#components_to_time_point) -=== +*** ### Obtaining a `time_point` from `y/m/d h:m:s` components +See http://stackoverflow.com/questions/31711782. -Write me +```c++ +using namespace std::chrono; +using namespace date; +// Component values (as obtained from an UI form, for example) +int y=2015, m=7, d=30, h=12, min=34, s=56; +system_clock::time_point = day_point(year(y)/m/d) + hours(h) + minutes(min) + seconds(s); +``` ### Obtaining `y/m/d h:m:s` components from a `time_point` -Write me +```c++ +using namespace date; +auto daypoint = floor(time); +auto ymd = year_month_day(daypoint); // calendar date +auto tod = make_time(time - daypoint); // Yields time_of_day type + +// Obtain individual components as integers +auto y = int(ymd.year()); +auto m = unsigned(ymd.month()); +auto d = unsigned(ymd.day()); +auto h = tod.hours().count(); +auto min = tod.minutes().count(); +auto s = tod.seconds().count(); +```