forked from futurewei-cloud/caerus-dikeCS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeUtil.hpp
60 lines (52 loc) · 1.51 KB
/
TimeUtil.hpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef TIME_UTIL_HPP
#define TIME_UTIL_HPP
#include <chrono>
#include <ctime>
#include <string>
#include <sstream>
#include <iomanip>
class TimeUtil{
public:
TimeUtil(){
}
~TimeUtil(){
}
std::string Now(){
std::ostringstream now;
time_t curr_time;
curr_time = time(NULL);
tm *tm_local = localtime(&curr_time);
now << std::to_string(tm_local->tm_year - 100) << "/";
now << std::setw(2) << std::setfill('0') << std::to_string(tm_local->tm_mon + 1) << "/";
now << std::setw(2) << std::setfill('0') << std::to_string(tm_local->tm_mday) << " ";
now << std::setw(2) << std::setfill('0') << std::to_string(tm_local->tm_hour) << ":";
now << std::setw(2) << std::setfill('0') << std::to_string(tm_local->tm_min) << ":";
now << std::setw(2) << std::setfill('0') << std::to_string(tm_local->tm_sec);
return now.str();
}
std::string Reset() {
std::string Reset("\033[0m");
return Reset;
}
std::string Red() {
std::string Red("\033[0;31m");
return Red;
}
std::string Green() {
std::string Green("\033[0;32m");
return Green;
}
std::string Yellow() {
std::string Yellow("\033[0;33m");
return Yellow;
}
std::string Blue() {
std::string Blue("\033[0;34m");
return Blue;
}
std::string Purple() {
std::string Purple("\033[0;35m");
return Purple;
}
};
#endif /* TIME_UTIL_HPP */