79188800

Date: 2024-11-14 12:53:42
Score: 1.5
Natty:
Report link
#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

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: winlinsuperjfdsao