41 using namespace std::chrono;
42 const auto now = system_clock::now();
43 const auto secs = time_point_cast<seconds>(now);
44 const auto frac_us = duration_cast<microseconds>(now - secs).count();
46 const std::time_t tt = system_clock::to_time_t(now);
48 gmtime_r(&tt, &tm_buf);
51 std::strftime(date_buf,
sizeof(date_buf),
"%Y-%m-%dT%H:%M:%S", &tm_buf);
53 if (frac_digits <= 0) {
54 return std::string(date_buf);
58 if (frac_digits > 6) {
64 int scaled =
static_cast<int>(frac_us);
65 for (
int i = 0; i < (6 - frac_digits); ++i) {
70 std::snprintf(frac_buf,
sizeof(frac_buf),
".%0*d", frac_digits, scaled);
71 return std::string(date_buf) + frac_buf;