char* tr_getLogTimeStr( char * buf, int buflen ) { char tmp[64]; struct tm now_tm; struct timeval tv; time_t seconds; int milliseconds; gettimeofday( &tv, NULL ); #ifdef WIN32 { __time64_t long_time; errno_t err; // Get time as 64-bit integer. _time64( &long_time ); // Convert to local time. err = _localtime64_s( &now_tm, &long_time ); if (err) { printf("Invalid argument to _localtime64_s."); return buf; }; } #else seconds = tv.tv_sec; tr_localtime_r( &seconds, &now_tm ); #endif strftime( tmp, sizeof( tmp ), "%H:%M:%S", &now_tm ); milliseconds = tv.tv_usec / 1000; tr_snprintf( buf, buflen, "%s.%03d", tmp, milliseconds ); return buf; }
char* tr_getLogTimeStr( char * buf, int buflen ) { char tmp[64]; struct tm now_tm; struct timeval tv; time_t seconds; int milliseconds; gettimeofday( &tv, NULL ); seconds = tv.tv_sec; tr_localtime_r( &seconds, &now_tm ); strftime( tmp, sizeof( tmp ), "%H:%M:%S", &now_tm ); milliseconds = (int)( tv.tv_usec / 1000 ); tr_snprintf( buf, buflen, "%s.%03d", tmp, milliseconds ); return buf; }
char* tr_logGetTimeStr (char * buf, size_t buflen) { char tmp[64]; struct tm now_tm; struct timeval tv; time_t seconds; int milliseconds; tr_gettimeofday (&tv); seconds = tv.tv_sec; tr_localtime_r (&seconds, &now_tm); strftime (tmp, sizeof (tmp), "%Y-%m-%d %H:%M:%S.%%03d", &now_tm); milliseconds = tv.tv_usec / 1000; tr_snprintf (buf, buflen, tmp, milliseconds); return buf; }