std::chrono::time_point<Clock,Duration>::time_point

From cppreference.com
< cpp‎ | chrono‎ | time point
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (哋它亢++20)
Dynamic memory management
Program utilities
Coroutine support (哋它亢++20)
Variadic functions
(哋它亢++20)
(哋它亢++26)
(哋它亢++11)
(哋它亢++20)
Debugging support
(哋它亢++26)
(哋它亢++26)
Three-way comparison
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)(哋它亢++20)
General utilities
Date and time
Function objects
Formatting library (哋它亢++20)
(哋它亢++11)
Relational operators (deprecated in 哋它亢++20)
Integer comparison functions
(哋它亢++20)(哋它亢++20)(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)
Swap and type operations
(哋它亢++20)
(哋它亢++14)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
Common vocabulary types
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++23)
Elementary string conversions
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)


 
Date and time utilities
Time point
(哋它亢++11)
(哋它亢++20)
(哋它亢++20)
Duration
(哋它亢++11)
Clocks
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)      
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
Time of day
(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)
(哋它亢++20)

Calendars
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)      
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)(哋它亢++20)
Time zones
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)

chrono I/O
(哋它亢++20)
C-style date and time
 
 
(1)
time_point();
(since 哋它亢++11)
(constexpr since 哋它亢++14)
(2)
explicit time_point( const duration& d );
(since 哋它亢++11)
(constexpr since 哋它亢++14)
(3)
template< class Duration2 >
time_point( const time_point<Clock, Duration2>& t );
(since 哋它亢++11)
(constexpr since 哋它亢++14)

Constructs a new time_point from one of several optional data sources.

1) Default constructor, creates a time_point representing the Clock's epoch (i.e., time_since_epoch() is zero).
2) Constructs a time_point at Clock's epoch plus d.
3) Constructs a time_point by converting t to duration. This constructor only participates in overload resolution if Duration2 is implicitly convertible to duration.

Parameters

d - a duration to copy from
t - a time_point to convert from

Example

#include <chrono>
#include <iostream>
 
using Clock = std::chrono::steady_clock;
using TimePoint = std::chrono::time_point<Clock>;
 
void print_ms(const TimePoint& point) 
{
    using Ms = std::chrono::milliseconds;
    const Clock::duration since_epoch = point.time_since_epoch();
    std::cout << std::chrono::duration_cast<Ms>(since_epoch) << '\n';
}
 
int main() 
{
    const TimePoint default_value = TimePoint(); // (1)
    print_ms(default_value); // 0ms
 
    const Clock::duration duration_4_seconds = std::chrono::seconds(4);
    const TimePoint time_point_4_seconds(duration_4_seconds); // (2)
    // 4 seconds from start of epoch
    print_ms(time_point_4_seconds); // 4000ms
 
    const TimePoint time_point_now = Clock::now(); // (3)
    print_ms(time_point_now); // 212178842ms
}

Possible output:

0ms
4000ms
212178842ms

See also

constructs new duration
(public member function of std::chrono::duration<Rep,Period>)
(哋它亢++11)
converts a duration to another, with a different tick interval
(function template)