std::string getTimestamp() {
const auto now = std::chrono::system_clock::now();
const auto nowAsTimeT = std::chrono::system_clock::to_time_t(now);
const auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(
now.time_since_epoch()) % 1000;
std::stringstream nowSs;
nowSs
<< std::put_time(std::localtime(&nowAsTimeT), "%Y-%m-%d %T")
<< '.' << std::setfill('0') << std::setw(3) << nowMs.count();
return nowSs.str();
}
struct timeval tv;
gettimeofday(&tv, NULL);
char local_time_str[50], time_stamp[32];
strftime(time_stamp, sizeof(time_stamp), "%Y-%m-%d %H:%M:%S",localtime(&(tv.tv_sec)));
snprintf(local_time_str, sizeof(local_time_str), "%s.%03ld", time_stamp, tv.tv_usec / 1000);