uint64_ttimestamp(timeunit unit) { // for C++11 and later auto now = std::chrono::system_clock::now(); auto timestamp_ms = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count(); auto us = static_cast<uint64_t>(timestamp_ms); uint64_t t = 0; switch (unit) { case timeunit::s: t = us2s(us); break; case timeunit::ms: t = us2ms(us); break; case timeunit::us: t = us; break; default: break; } return t; }
-------------------------------------------TestTimestamp-------------------------------------------- current timestamp( s): 1716129274 current timestamp(ms): 1716129274848 current timestamp(us): 1716129274848863