将 NTFS 时间戳转换为 FAT 时间戳
我正在编写一个文件传输应用程序,我需要将文件从 NTFS 复制到 FAT 驱动器。从 http://support.microsoft.com/kb/127830 阅读,我了解到复制到 FAT 硬盘驱动器时,诸如 #11/29/2004 7:31:06 PM, 250ms# 之类的时间应转换为 #11/29/2004 7:31:08 PM, 0ms#。然而,实际发生的情况是文件时间被截断为#11/29/2004 7:31:06 PM, 0ms#。
我在这里错过了什么吗?时间什么时候被截断,什么时候被四舍五入?
编辑:添加代码示例:
IO.File.GetLastWriteTimeUtc(Source)
我的 NTFS->FAT 函数是:
Function NTFSToFATTime(ByVal NTFSTime As Date) As Date
Return (New Date(NTFSTime.Year, NTFSTime.Month, NTFSTime.Day, NTFSTime.Hour, NTFSTime.Minute, NTFSTime.Second).AddSeconds(If(NTFSTime.Millisecond = 0, NTFSTime.Second Mod 2, 2 - (NTFSTime.Second Mod 2))))
End Function
I'm writing a file transfer application, and I need to copy files from NTFS to FAT drives. Reading from http://support.microsoft.com/kb/127830, I understand that a time such as #11/29/2004 7:31:06 PM, 250ms# should get translated to #11/29/2004 7:31:08 PM, 0ms# when copying to a FAT hard drive. However, what actually happens is that the file time gets truncated to #11/29/2004 7:31:06 PM, 0ms#.
Am I missing something here? When does the time get truncated, and when does it get rounded?
Edit: Add a code sample:
IO.File.GetLastWriteTimeUtc(Source)
My NTFS->FAT function is:
Function NTFSToFATTime(ByVal NTFSTime As Date) As Date
Return (New Date(NTFSTime.Year, NTFSTime.Month, NTFSTime.Day, NTFSTime.Hour, NTFSTime.Minute, NTFSTime.Second).AddSeconds(If(NTFSTime.Millisecond = 0, NTFSTime.Second Mod 2, 2 - (NTFSTime.Second Mod 2))))
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
技术背景: FAT基本上使用2个字节来存储在目录项中创建文件的时间(小时/分钟/秒)。它使用该字段的低 4 位表示秒,其中 0-29 的值有效,并乘以 2 得到最终值。因此,秒必然是偶数。
很奇怪,但我的猜测是这些文档要么是错误的,要么没有引用您正在使用的 API。您的时间戳刚刚被截断。不确定您使用哪个 API 来创建 FAT 文件(查看它的文档可能会很有用)。
Technical backgrounder: Basically FAT uses 2 bytes to store the time (hours/minutes/seconds) of the file create in the directory entry. It uses the low 4 bits of this field for the seconds, for which values of 0-29 are valid, and are multiplied by 2 to get the final value. Thus by necessity, seconds will be an even number.
Weird, but my guess is that the docs are either wrong or don't refer to the API you're using. Your timestamp is just getting truncated. Not sure which API you're using to create the FAT file (might be useful to see the docs for it).