32std::ostream &
timestamp(std::ostream &out,
const std::chrono::time_zone *tz)
40 typedef std::chrono::system_clock myclock;
41 static char YMDHMS[30];
42 static std::chrono::time_point<myclock,std::chrono::milliseconds> old_time;
43 static const std::chrono::time_zone *old_tz =
nullptr;
44 const auto cur_time = time_point_cast<std::chrono::milliseconds>(myclock::now());
45 if (cur_time != old_time || tz != old_tz)
47#ifdef STD_FORMAT_CHRONO_
48 constexpr const std::string_view TIMESTAMP_FMT =
"{:%Y/%m/%d %H:%M:%S}";
49 auto tm_str = tz? std::format(TIMESTAMP_FMT, tz->to_local(cur_time)): std::format(TIMESTAMP_FMT, cur_time);
50 std::strcpy(YMDHMS, tm_str.c_str());
52 auto d = imaxdiv(cur_time.time_since_epoch().count(), 1000);
54 std::sprintf(YMDHMS + std::strftime(YMDHMS,
sizeof YMDHMS,
"%Y/%m/%d %H:%M:%S", std::localtime(&t)),
".%03" PRIdMAX, d.rem);