#include <chrono>
#include <iostream>
#include <iomanip>
template <typename Duration, typename Clock>
Duration get_duration_since_epoch()
{
const auto tp = std::chrono::time_point_cast<Duration>(Clock::now());
return tp.time_since_epoch();
}
int main()
{
using float_sec_t = std::chrono::duration<double, std::chrono::seconds::period>;
// integer seconds
std::cout << get_duration_since_epoch<std::chrono::seconds, std::chrono::system_clock>() << std::endl;
// double seconds
std::cout << std::setprecision(15) << get_duration_since_epoch<float_sec_t , std::chrono::system_clock>() << std::endl;
}
https://wandbox.org/permlink/HULwKXGyc5m0pIVQ