Convert Windows Filetime to second in Unix/Linux(在 Unix/Linux 中将 Windows 文件时间转换为秒)
问题描述
我有一个跟踪文件,每个事务时间都以 Windows 文件时间格式表示.这些时间数字是这样的:
I have a trace file that each transaction time represented in Windows filetime format. These time numbers are something like this:
- 128166372003061629
- 128166372016382155
- 128166372026382245
您能否告诉我 Unix/Linux 中是否有任何 C/C++ 库可以从这些数字中提取实际时间(特别是秒)?我可以编写自己的提取函数吗?
Would you please let me know if there are any C/C++ library in Unix/Linux to extract actual time (specially second) from these numbers ? May I write my own extraction function ?
推荐答案
很简单:windows 纪元从 1601-01-01T00:00:00Z 开始.它比 UNIX/Linux 时代 (1970-01-01T00:00:00Z) 早 11644473600 秒.Windows 滴答以 100 纳秒为单位.因此,从 UNIX epoch 中获取秒数的函数将如下所示:
it's quite simple: the windows epoch starts 1601-01-01T00:00:00Z. It's 11644473600 seconds before the UNIX/Linux epoch (1970-01-01T00:00:00Z). The Windows ticks are in 100 nanoseconds. Thus, a function to get seconds from the UNIX epoch will be as follows:
#define WINDOWS_TICK 10000000
#define SEC_TO_UNIX_EPOCH 11644473600LL
unsigned WindowsTickToUnixSeconds(long long windowsTicks)
{
return (unsigned)(windowsTicks / WINDOWS_TICK - SEC_TO_UNIX_EPOCH);
}
这篇关于在 Unix/Linux 中将 Windows 文件时间转换为秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Unix/Linux 中将 Windows 文件时间转换为秒
基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
