[英]How to convert milli seconds time to FILETIME in c++
I have a time in secs (ex:1505306792). 我有一段时间(例如:1505306792)。
How to convert this into FILETIME? 如何将其转换为FILETIME?
Here is the code i have tried 这是我试过的代码
INT64 timer64 = 1505306792;
timer64 = timer64 *1000 *10000;
ULONGLONG xx = timer64;
FILETIME fileTime;
ULARGE_INTEGER uliTime;
uliTime.QuadPart = xx;
fileTime.dwHighDateTime = uliTime.HighPart;
fileTime.dwLowDateTime = uliTime.LowPart;
This result FILETIME is coming as 1648-09-13 15:34:00 此结果FILETIME将于1648-09-13 15:34:00发布
I am expecting this date to be 2017-09-13 12:46:31 . 我期待这个日期是2017-09-13 12:46:31。 I am getting the same when using online converters.
我在使用在线转换器时也是如此。
Any idea how to solve this? 不知道怎么解决这个问题?
I have seen some answers using boost, but it is available in my project. 我已经看到了一些使用boost的答案,但它在我的项目中可用。
It's about adding 116444736000000000, see How To Convert a UNIX time_t to a Win32 FILETIME or SYSTEMTIME : 这是关于添加116444736000000000,请参阅如何将UNIX time_t转换为Win32 FILETIME或SYSTEMTIME :
#include <winbase.h>
#include <winnt.h>
#include <time.h>
void UnixTimeToFileTime(time_t t, LPFILETIME pft)
{
// Note that LONGLONG is a 64-bit value
LONGLONG ll;
ll = Int32x32To64(t, 10000000) + 116444736000000000;
pft->dwLowDateTime = (DWORD)ll;
pft->dwHighDateTime = ll >> 32;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.