-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChron.h
38 lines (30 loc) · 948 Bytes
/
Chron.h
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
32
33
34
35
36
37
38
// EmbedErr
// By: Sina Tashakkori, QVLx Labs
#ifndef CHRON_H
#define CHRON_H
#include <chrono>
#include <ctime>
class Chron {
public:
static std::chrono::system_clock::time_point getCurrentTime() {
return std::chrono::system_clock::now();
}
static std::string timeToString(
const std::chrono::system_clock::time_point& tp) {
std::time_t time = std::chrono::system_clock::to_time_t(tp);
std::tm tm_struct;
#ifdef _WIN32
gmtime_s(&tm_struct, &time);
#else
std::gmtime_r(&time, &tm_temp);
#endif
std::ostringstream oss;
oss << std::put_time(&tm_struct, "%Y-%m-%d %H:%M:%S");
return oss.str();
}
static std::time_t toTimeT(
const std::chrono::system_clock::time_point& timePoint) {
return std::chrono::system_clock::to_time_t(timePoint);
}
};
#endif