Namespaces
Variants
Actions

std::chrono::duration<Rep,Period>::count

From cppreference.com
< cpp‎ | chrono‎ | duration
 
C++
 
Date and time library
Time point
(C++11)
(C++20)
Duration
(C++11)
Clocks
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Time of day
(C++20)(C++20)
(C++20)(C++20)
(C++20)
Calendar
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
chrono I/O
(C++20)

 
std::chrono::duration
constexpr rep count() const;
(since C++11)

Returns the number of ticks for this duration.

Contents

[edit] Parameters

(none)

[edit] Return value

The number of ticks for this duration.

[edit] Example

#include <chrono>
#include <iostream>
 
int main()
{
    std::chrono::milliseconds ms{3}; / 3 milliseconds
    / 6000 microseconds constructed from 3 milliseconds
    std::chrono::microseconds us = 2 * ms;
    / 30Hz clock using fractional ticks
    std::chrono::duration<double, std::ratio<1, 30>> hz30(3.5);
 
    std::cout << "3 ms duration has " << ms.count() << " ticks\n"
              << "6000 us duration has " << us.count() << " ticks\n"
              << "3.5 30Hz duration has " << hz30.count() << " ticks\n";       
}

Output:

3 ms duration has 3 ticks
6000 us duration has 6000 ticks
3.5 30Hz duration has 3.5 ticks

[edit] See also

converts a duration to another, with a different tick interval
(function template) [edit]

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant