function template
<chrono>

std::chrono::time_point_cast

template <class ToDuration, class Clock, class Duration>  time_point<Clock,ToDuration> time_point_cast (const time_point<Clock,Duration>& tp);
Time_point cast
Converts the value of tp into a time_point type with a different duration internal object, taking into account differences in their durations's periods.

The function uses duration_cast to convert the internal duration objects.

Notice that the function's first template parameter is not the return type, but its duration component.

Parameters

tp
A time_point object.

Return value

The value of tp converted into an object of type time_point<Clock,ToDuration>.
time_point<Clock,ToDuration> is a time_point with the same Clock type as tp.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// time_point_cast
#include <iostream>
#include <ratio>
#include <chrono>

int main ()
{
  using namespace std::chrono;

  typedef duration<int,std::ratio<60*60*24>> days_type;

  time_point<system_clock,days_type> today = time_point_cast<days_type>(system_clock::now());

  std::cout << today.time_since_epoch().count() << " days since epoch" << std::endl;

  return 0;
}

Possible output:
15490 days since epoch


See also