The accepted answer is a good answer (which I approved).
Here is an alternative wording using the same library :
#include "date.h" #include <string> std::string make_date_string() { return date::format("%F", std::chrono::system_clock::now()); }
which creates std::string with the format "2017-07-09" . This particular formulation is good in that you do not need to explicitly create std::ostringstream , and you can easily change the format to whatever you like, for example:
return date::format("%m/%d/%Y", std::chrono::system_clock::now());
which now returns "07/09/2017" .
source share