I wrote a C ++ function to get the current time in a format HH:MM:SS. How to add milliseconds or nanoseconds, so I can have a format, for example HH:MM:SS:MMM? If this is not possible, a function that returns the current time in ms will also be good. Then I can calculate the relative time intervals between the two log points.
string get_time()
{
time_t t = time(0);
struct tm * now = localtime(&t);
std::stringstream sstm;
sstm << (now->tm_hour) << ':' << (now->tm_min) << ':' << now->tm_sec;
string s = sstm.str();
return s;
}
source
share