Commit feb71130b8068c89de18f906aa583a8cfaebf79a

Authored by Jordi Inglada
1 parent 428a6d22
Exists in master

Add now_str function

Showing 1 changed file with 8 additions and 0 deletions   Show diff stats
include/cbutils.h
... ... @@ -23,6 +23,7 @@
23 23 #include <vector>
24 24 #include <random>
25 25 #include <cassert>
  26 +#include <chrono>
26 27 namespace cbutils
27 28 {
28 29 // ----------------- String manipulation ---------------------------------------
... ... @@ -125,6 +126,13 @@ T uniform(T minvalue, T maxvalue)
125 126 // ----------------- Miscellaneous ---------------------------------------------
126 127 namespace misc
127 128 {
  129 +std::string now_str()
  130 +{
  131 + auto now_t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
  132 + std::stringstream result;
  133 + result << std::put_time(std::localtime(&now_t), "%F %T") << " -- ";
  134 + return result.str();
  135 +}
128 136 }// end ns misc
129 137 }//end ns cbutils
130 138 #endif
... ...