std::chrono::system_clock::to_time_t

Converts t to a std::time_t type.

# Declarations

static std::time_t to_time_t( const time_point& t ) noexcept;

(since C++11)

# Parameters

# Return value

A std::time_t value representing t.

# Example

#include <chrono>
#include <ctime>
#include <iostream>
#include <thread>
using namespace std::chrono_literals;
 
int main()
{
    // The old way
    std::time_t oldt = std::time({});
 
    std::this_thread::sleep_for(2700ms);
 
    // 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";
}

# See also