#include <timeutils.h>
string TimeUtils::timeString |
( |
const std::chrono::system_clock::time_point & |
tp | ) |
|
39 time_t t = std::chrono::system_clock::to_time_t(tp);
40 string ts = ctime(&t);
41 ts.resize(ts.size()-1);
std::chrono::system_clock::time_point TimeUtils::makeTimePoint |
( |
int |
year, |
|
|
int |
mon, |
|
|
int |
day, |
|
|
int |
hour, |
|
|
int |
min, |
|
|
int |
sec |
|
) |
| |
49 time.tm_year = year-1900;
57 std::time_t tt = std::mktime(&time);
60 throw "no valid system time";
76 return std::chrono::system_clock::from_time_t(tt);
std::chrono::system_clock::time_point TimeUtils::timePointUtc |
( |
| ) |
|
83 auto now = std::chrono::system_clock::now();
84 time_t tnow = std::chrono::system_clock::to_time_t(now);
85 tm *timeUtc = std::gmtime(&tnow);
86 return std::chrono::system_clock::from_time_t(std::mktime(timeUtc));
double TimeUtils::secondsSinceEpoch |
( |
| ) |
|
97 auto now = std::chrono::system_clock::now();
102 std::chrono::system_clock::duration elapsedSeconds = now-epoch;
103 return std::chrono::duration_cast<std::chrono::milliseconds>(elapsedSeconds).
count()/1000.0;
int count
Definition: rw_test.cpp:36
std::chrono::system_clock::time_point timePointUtc()
Definition: timeutils.cpp:80
std::chrono::system_clock::time_point makeTimePoint(int year, int mon, int day, int hour, int min, int sec)
Definition: timeutils.cpp:46
std::chrono::system_clock::duration TimeUtils::secondsSinceMidnight |
( |
| ) |
|
109 auto now = std::chrono::system_clock::now();
111 time_t tnow = std::chrono::system_clock::to_time_t(now);
112 tm *date = std::localtime(&tnow);
116 auto midnight = std::chrono::system_clock::from_time_t(std::mktime(date));
void TimeUtils::testSecondsSinceMidnight |
( |
| ) |
|
127 auto hours = std::chrono::duration_cast<std::chrono::hours>(since_midnight);
128 auto minutes = std::chrono::duration_cast<std::chrono::minutes>(since_midnight - hours);
129 auto seconds = std::chrono::duration_cast<std::chrono::seconds>(since_midnight - hours - minutes);
130 auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(since_midnight - hours - minutes - seconds);
131 auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(since_midnight - hours - minutes - seconds - milliseconds);
132 auto nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(since_midnight - hours - minutes - seconds - milliseconds - microseconds);
135 std::cout << hours.count() <<
"h ";
136 std::cout << minutes.count() <<
"m ";
137 std::cout << seconds.count() <<
"s ";
138 std::cout << milliseconds.count() <<
"ms ";
139 std::cout << microseconds.count() <<
"us ";
140 std::cout << nanoseconds.count() <<
"ns\n";
std::chrono::system_clock::duration secondsSinceMidnight()
Definition: timeutils.cpp:108
The documentation for this class was generated from the following files: