public member function
<chrono>

std::chrono::duration::count

constexpr rep count() const;
Get count
Returns the internal count (i.e., the representation value) of the duration object.

The value returned is the current value of the internal representation expressed in terms of the class's period interval, which are not necessarily seconds.

Parameters

none

Return value

The representation value of the object as a count of periods.
rep is a member type, defined as an alias of its first class template parameter (Rep), which is an arithmetic type (or a class emulating an arithmetic type).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// duration::count
#include <iostream>     // std::cout
#include <chrono>       // std::chrono::seconds, std::chrono::milliseconds
                        // std::chrono::duration_cast

int main ()
{
  using namespace std::chrono;
  // std::chrono::milliseconds is an instatiation of std::chrono::duration:
  milliseconds foo (1000); // 1 second
  foo*=60;

  std::cout << "duration (in periods): ";
  std::cout << foo.count() << " milliseconds.\n";

  std::cout << "duration (in seconds): ";
  std::cout << foo.count() * milliseconds::period::num / milliseconds::period::den;
  std::cout << " seconds.\n";

  return 0;
}


Output:
duration (in periods): 60000 milliseconds
duration (in seconds): 60 seconds

See also