本文介绍了将Unix/Linux时间转换为Windows FILETIME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我再次从Windows迁移到Linux,我必须将Windows移植到计算NTP时间的函数.看起来很简单,但格式为Windows FILETIME格式.我有点知道有什么区别,但是到目前为止,我无法正确地将Linux时间转换为Windows filetime格式.有人对如何执行此操作有任何想法吗?

I am once again going from Windows to Linux, I have to port a function from Windows to Linux that calculates NTP time. Seems simple but the format is in Windows FILETIME format. I sort of have an idea what the differences are but so far I can not correctly convert my Linux time to the windows filetime format. Does anyone have any ideas on how to do this?

我看过一些有关如何执行此操作的文章,但是它们都使用win32函数,而我不能使用它们!如果没有意义,我可以发布Windows代码,谢谢.

I have seen some articles on how to do this but they all use win32 functions and I can't use them! I can post the windows code if this makes no sense, thanks.

他们还采用当前时间,并从1900年1月1日开始将其减去以获得NTP的增量,我想在Linux中我只是将const unsigned long EPOCH = 2208988800UL加到我的时间上以获得此结果?

They also take the current time and subtract it from January 1st 1900 to get the delta to find NTP, I would assume in Linux I just add the const unsigned long EPOCH = 2208988800UL to my time to get this result?

谢谢.

推荐答案

FILETIME 结构说明了它的含义.基本想法是,Windows FILETIME从1月1日1601开始以10 秒(100纳秒的间隔)进行计数(为什么1601?不知道...).在Linux中,您可以使用#include <sys/time.h> /** * number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC */ #define EPOCH_DIFF 11644473600LL unsigned long long getfiletime() { struct timeval tv; unsigned long long result = EPOCH_DIFF; gettimeofday(&tv, NULL); result += tv.tv_sec; result *= 10000000LL; result += tv.tv_usec * 10; return result; }

这篇关于将Unix/Linux时间转换为Windows FILETIME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 05:32