记录一下,方便取用
#include <thread>
#ifdef _WIN32
#include <Windows.h>
const char* timenow()
{
static thread_local char str[32];
SYSTEMTIME st;
GetLocalTime(&st);
snprintf(str,32,"%d-%d-%d %02d:%02d:%02d.%03d",st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
return str;
}
#else
#include <sys/time.h>
const char* timenow()
{
static thread_local char str[32];
struct timeval time;
gettimeofday(&time, NULL);
struct tm* p = localtime(&(time.tv_sec));
snprintf(str, 32, "%d-%d-%d %02d:%02d:%02d.%03ld", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, time.tv_usec / 1000);
return str;
}
#endif // _WIN32
#define TIMENOW timenow()
标签:-%,02d,C++,st,char,毫秒,tm,时间,str
From: https://www.cnblogs.com/SupperMary/p/16804744.html