获取本地时间 精确到毫秒
string GetSysUsecTimeHMS()
{
char szBuf[256] = {0};
struct timeval tv;
struct timezone tz;
struct tm *p;
gettimeofday(&tv, &tz);
p = localtime(&tv.tv_sec);
snprintf(szBuf, 256, "%02d-%02d-%02d %02d:%02d:%02d.%06ld", p->tm_year + 1900, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec);
return szBuf;
}
调用:
printf("%s\n", GetSysUsecTimeHMS().c_str());