C++获取13位的时间戳(Linux平台和windows平台)

Linux平台:

static int64_t GetUnixTime()
{
	int64_t times = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count();
	return times;
}

windows平台:

static __int64 GetUnixTime()
{
	string nowTimeUnix;
	string cs_uninxtime;
	string cs_milliseconds;
	SYSTEMTIME sysTime;
	GetLocalTime(&sysTime);
	time_t unixTime;
	time(&unixTime);
	char buf[30], buf1[30];
	sprintf_s(buf, sizeof(buf), "%I64d", (INT64)unixTime);
	sprintf_s(buf1, sizeof(buf1), "%03I64d", (INT64)sysTime.wMilliseconds);
	nowTimeUnix = string(buf) + string(buf1);
	return _atoi64(nowTimeUnix.c_str());
}

 

你可能感兴趣的:(C++)