9 namespace DateTimeUtils {
14 [[
nodiscard]]
static std::string
toString(
const std::time_t&
time,
const std::string_view& format =
"%Y-%m-%d %H:%M:%S") {
23 return std::string{
buffer};
33 iss >> std::get_time(&
tm, format.data());
35 return std::mktime(&
tm);
41 [[
nodiscard]]
static std::string
now(
const std::string_view& format =
"%Y-%m-%d %H:%M:%S") {
42 const std::time_t
tm = std::time(
nullptr);
46 [[
deprecated(
"Use DateTimeUtils::now() instead")]]
static std::string now(const std::string_view &format="%Y-%m-%d %H:%M:%S")
returns current date and time as a string with a specific format
static std::string toString(const std::time_t &time, const std::string_view &format="%Y-%m-%d %H:%M:%S")
Converts an std::time_t to a string date time with a specific format.
static std::string currentDateTime(const std::string_view &format="%Y-%m-%d %H:%M:%S")
static std::time_t fromString(const std::string &dateTimeStr, const std::string_view &format="%Y-%m-%d %H:%M:%S")
Converts a string date time with a specific format to an std::time_t.