Get the current day using a chronograph

C ++ 11 provides a function to return the current time. However, I cannot find the return function for the current day. And I use boost for this.

boost::gregorian::date TODAY = boost::gregorian::day_clock::local_day(); 

Is there a way to achieve the same result with a chronograph?

EDIT: I want to use time_point to represent the current day. This means that the hour, minute and second are zero 2013-07-31 00:00:00

+4
source share
1 answer

Chronos does not spread the problem today; this is really not the goal. The separation between dates and "time" is the day. And Chrono does not determine the type of day.

But you could just divide the time in hours by 24. Or better yet, define your own typedef duration and use this:

 typedef std::duration<std::uint32_t, std::ratio<3600 * 24>> day; 

Then just use time_point with this type:

 std::chrono::time_point<std::chrono::system_clock, day> day_getter; day_getter.time_since_epoch(); 
+6
source

Source: https://habr.com/ru/post/1494412/


All Articles