diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index 09334242e8..f804b319a5 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -15,6 +16,7 @@ #include #include +#include #include #include @@ -278,21 +280,11 @@ static double GetSystemTimeAsDouble() static std::string SystemTimeAsDoubleToString(double time) { // revert adjustments from GetSystemTimeAsDouble() to get a normal Unix timestamp again - time_t seconds = static_cast(time) + DOUBLE_TIME_OFFSET; - errno = 0; - tm* local_time = localtime(&seconds); - if (errno != 0 || !local_time) - return ""; + const time_t seconds = static_cast(time) + DOUBLE_TIME_OFFSET; + const tm local_time = fmt::localtime(seconds); -#ifdef _WIN32 - wchar_t tmp[32] = {}; - wcsftime(tmp, std::size(tmp), L"%x %X", local_time); - return WStringToUTF8(tmp); -#else - char tmp[32] = {}; - strftime(tmp, sizeof(tmp), "%x %X", local_time); - return tmp; -#endif + // fmt is locale agnostic by default, so explicitly use current locale. + return fmt::format(std::locale{""}, "{:%x %X}", local_time); } static std::string MakeStateFilename(int number);