1.linux C++ 获取当前系统时间(毫秒级)
#include <stdio.h>
#include <sys/time.h>
using namespace std;
void sysTime(string ¤tTime)
{
struct timeval tv;
struct timezone tz;
struct tm *t;
char * curTime;
gettimeofday(&tv, &tz);
t = localtime(&tv.tv_sec);
sprintf(curTime, "%d-%d-%d_%d%d%d%ld", 1900+t->tm_year, 1+t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec);
currentTime = curTime;
}
int main()
{
string currentTime;
sysTime(currentTime);
cout<<"current time :"<<currentTime<<endl;
return 0;