mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-05 21:54:27 +02:00
Updated Examples and Recipes (markdown)
@@ -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)
|
||||
|
||||
===
|
||||
***
|
||||
|
||||
<a name="time_point_to_components"></a>
|
||||
### 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);
|
||||
```
|
||||
|
||||
<a name="components_to_time_point">
|
||||
### Obtaining `y/m/d h:m:s` components from a `time_point`
|
||||
|
||||
Write me
|
||||
```c++
|
||||
using namespace date;
|
||||
auto daypoint = floor<days>(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();
|
||||
```
|
||||
|
Reference in New Issue
Block a user