From 931380105b6ec88ce86912f3139c5b1fb2fb280b Mon Sep 17 00:00:00 2001 From: taynpg Date: Mon, 7 Apr 2025 23:11:32 +0800 Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A=E6=B7=BB=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=97=B6=E9=97=B4=E6=88=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/of_util.h | 2 ++ src/of_util.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/of_util.h b/include/of_util.h index 2427828..4bbfd8e 100644 --- a/include/of_util.h +++ b/include/of_util.h @@ -48,6 +48,8 @@ public: static ofString now_time(); static ofString get_file_size(long long bytes); static ofString get_uuid(); + static uint64_t get_timestamp_ms(); + static uint64_t get_timestamp_s(); }; class CMutBuffer diff --git a/src/of_util.cpp b/src/of_util.cpp index c4ac551..79071f2 100644 --- a/src/of_util.cpp +++ b/src/of_util.cpp @@ -150,6 +150,20 @@ ofString OfUtil::get_uuid() #endif } +uint64_t OfUtil::get_timestamp_ms() +{ + auto now = std::chrono::system_clock::now(); + uint64_t ms = std::chrono::duration_cast(now.time_since_epoch()).count(); + return ms; +} + +uint64_t OfUtil::get_timestamp_s() +{ + auto now = std::chrono::system_clock::now(); + uint64_t s = std::chrono::duration_cast(now.time_since_epoch()).count(); + return s; +} + #ifdef _WIN32 std::string CCodec::u8_to_ansi(const std::string& str) {