1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
   | #include <time.h> #include <sys/time.h> string get_time() { 	string time; 	timeval tv; 	gettimeofday(&tv, NULL);
  	struct tm* ptm; 	ptm = localtime(&(tv.tv_sec));
  	char time_string[40]; 	long milliseconds;
  	strftime(time_string, sizeof(time_string), "%Y-%m-%d-%H-%M-%S-", ptm); 	milliseconds = tv.tv_usec / 1000;
  	time = time_string + to_string(milliseconds);
  	return time; }
   |