Juan Dent
Juan Dent

Reputation: 449

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

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>)??

Upvotes: 3

Views: 296

Answers (1)

Aykhan Hagverdili
Aykhan Hagverdili

Reputation: 29985

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.

Upvotes: 9

Related Questions