在我的C++ windows应用程序中,我将SYSTEMTIME转换为格式化字符串,如下所示:
SYSTEMTIME systemTime;
GetSystemTime(&systemTime);
char pSystemTime[50];
sprintf_s(pSystemTime, 50, "%04d%02d%02d%02d%02d%02d%03u\0", systemTime.wYear, systemTime.wMonth,
systemTime.wDay, systemTime.wHour,
systemTime.wMinute, systemTime.wSecond,
systemTime.wMilliseconds);现在,自UNIX时代以来,我的时间以毫秒为单位。
long time = 1442524186; //for example如何将这么长的时间转换为SYSTEMTIME,以便也可以将其格式化为字符串?
发布于 2015-09-17 17:51:37
static UINT64 FileTimeToMillis(const FILETIME &ft)
{
ULARGE_INTEGER uli;
uli.LowPart = ft.dwLowDateTime; // could use memcpy here!
uli.HighPart = ft.dwHighDateTime;
return static_cast<UINT64>(uli.QuadPart/10000);
}
static void MillisToSystemTime(UINT64 millis, SYSTEMTIME *st)
{
UINT64 multiplier = 10000;
UINT64 t = multiplier * millis;
ULARGE_INTEGER li;
li.QuadPart = t;
// NOTE, DON'T have to do this any longer because we're putting
// in the 64bit UINT directly
//li.LowPart = static_cast<DWORD>(t & 0xFFFFFFFF);
//li.HighPart = static_cast<DWORD>(t >> 32);
FILETIME ft;
ft.dwLowDateTime = li.LowPart;
ft.dwHighDateTime = li.HighPart;
::FileTimeToSystemTime(&ft, st);
}来源:https://stackoverflow.com/a/11123106/2385309
编辑:还请参阅:https://stackoverflow.com/a/26486180/2385309,您可能需要为Epoch时间毫秒增加/减去11644473600000
发布于 2019-10-31 05:03:36
在MillisToSystemTime中,行应该是这样的:
UINT64 t = multiplier * millis + 116444736000000000https://stackoverflow.com/questions/32636309
复制相似问题