系统时间的获取_ms
1.windows
#include <windows.h>
string getTime() {
SYSTEMTIME st;
GetLocalTime(&st);
string tmp = to_string(st.wYear) + "-" + to_string(st.wMonth) + "-" + to_string(st.wDay) + "-" + to_string(st.wHour) + "-" + to_string(st.wMinute) + "-" + to_string(st.wSecond) + "-" + to_string(st.wMilliseconds);
return tmp;
}
2.linux
#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;
}