mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 02:32:36 +01:00
45 lines
816 B
C++
45 lines
816 B
C++
#pragma once
|
|
|
|
#include <ctime>
|
|
#include <string>
|
|
|
|
namespace date_time
|
|
{
|
|
static inline tm get_time(time_t* _time)
|
|
{
|
|
tm buf;
|
|
time_t t = time(_time);
|
|
#ifdef _MSC_VER
|
|
localtime_s(&buf, &t);
|
|
#else
|
|
buf = *localtime(&t);
|
|
#endif
|
|
return buf;
|
|
}
|
|
|
|
static inline std::string current_time()
|
|
{
|
|
char str[80];
|
|
tm now = get_time(0);
|
|
strftime(str, sizeof(str), "%c", &now);
|
|
return str;
|
|
}
|
|
|
|
template<char separator = 0>
|
|
static inline std::string current_time_narrow()
|
|
{
|
|
char str[80];
|
|
tm now = get_time(0);
|
|
|
|
std::string parse_buf;
|
|
|
|
if constexpr(separator != 0)
|
|
parse_buf = std::string("%Y") + separator + "%m" + separator + "%d" + separator + "%H" + separator + "%M" + separator + "%S";
|
|
else
|
|
parse_buf = "%Y%m%d%H%M%S";
|
|
|
|
strftime(str, sizeof(str), parse_buf.c_str(), &now);
|
|
return str;
|
|
}
|
|
}
|