blob: bbdc3137db50228fbd74bd0f728923145f60300a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include "Time.hpp"
#include <ctime>
std::string StringifyTimePoint(std::chrono::time_point<std::chrono::system_clock> tp)
{
auto t = std::chrono::system_clock::to_time_t(tp);
char data[32];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations" // C++ doesn't have std::localtime_s
std::strftime(data, sizeof(data), "%Y-%m-%d %H:%M:%S", std::localtime(&t));
#pragma clang diagnostic pop
return std::string(data);
}
std::string StringifyTimeStamp(int64_t timeStamp)
{
if (timeStamp == 0) {
return "";
}
namespace chrono = std::chrono;
using Clock = chrono::system_clock;
chrono::milliseconds d{ timeStamp };
chrono::time_point<chrono::system_clock> tp{ d };
return StringifyTimePoint(tp);
}
|