now() cannot be converted to sys_days! I need today's date from now()

Viewed 103

Having trouble with:

auto n = std::chrono::system_clock::now();
std::chrono::sys_days sd = n;

Why ? n is a time_point and sd is also time_point (actually time_point<system_clock, days>)??

1 Answers

Here's how you do it:

#include <chrono>

int main() {
  using namespace std::chrono;
  auto const n = system_clock::now();
  sys_days sd = floor<days>(n);
}

Did I know this off the top of my head? No, of course not. It was in the examples of cppreference.com.

Related