Double-precision Unix timestamps in C++

Dealing with Unix timestamps in seconds can often be convenient. It’s also quite clean using chrono:

#include <chrono>

double unix() {
  auto now = std::chrono::system_clock::now();
  return std::chrono::duration<double>(now.time_since_epoch()).count();
}

To be fair, the standard doesn’t specify what the epoch is. But it’ll nearly always be consistent with Unix time.

Home