< cpp‎ | chrono‎ | system clock
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (C++20)
Dynamic memory management
Program utilities
Coroutine support (C++20)
Variadic functions
Debugging support
Three-way comparison
General utilities
Date and time
Function objects
Formatting library (C++20)
Relational operators (deprecated in C++20)
Integer comparison functions
Swap and type operations
Common vocabulary types
Elementary string conversions

static std::time_t to_time_t( const time_point& t ) noexcept;
(since C++11)

Converts t to a std::time_t type.

If std::time_t has lower precision, it is implementation-defined whether the value is rounded or truncated.


[edit] Parameters

t - system clock time point to convert

[edit] Return value

A std::time_t value representing t.

[edit] Example

Get the current time as a std::time_t two ways.

#include <chrono>
#include <ctime>
#include <iostream>
#include <thread>
using namespace std::chrono_literals;
int main()
    // The old way
    std::time_t oldt = std::time({});
    // The new way
    auto const now = std::chrono::system_clock::now();
    std::time_t newt = std::chrono::system_clock::to_time_t(now);
    std::cout << "newt - oldt == " << newt - oldt << " s\n";

Possible output:

newt - oldt == 3 s

[edit] See also

converts std::time_t to a system clock time point
(public static member function) [edit]