在 Unix/Linux 中将 Windows 文件时间转换为秒 [英] Convert Windows Filetime to second in Unix/Linux

查看:19
本文介绍了在 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 文件时间转换为秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆