Get Last Write Time返回一个奇怪的值 [英] Get Last Write Time is returning a strange value
问题描述
我试图在Windows 7中获取文件的最后修改日期 - 我刚刚编辑它,所以在属性中,上次修改的值被列为 11/30/2013 4: 55分
。
I'm trying to get the last modified date of a file in Windows 7 - I just edited it, so in the properties, the Last Modified value is listed as 11/30/2013 4:55 PM
.
但是,当我使用以下方式访问该文件时:
However, when I access the file using:
DateTime lastMod = File.GetLastWriteTime(file);
输出值:
MessageBox.Show(lastMod.toString());
这总是给出 12/31/1600 6:00:00 PM
,无论使用哪个文件,无论创建时间,修改时间等。
This always gives 12/31/1600 6:00:00 PM
, regardless of which file I'm working with, regardless of creation time, modification time, etc.
推荐答案
p>我怀疑你使用的是错误的文件名。 GetLastWriteTime $的文档c $ c>
指定:
I suspect you're using the wrong file name. The documentation for GetLastWriteTime
specifies:
如果路径参数中所述的文件不存在,此方法返回公元1601年1月1日凌晨12:00午12:00(UTC),调整为当地时间。
If the file described in the path parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC), adjusted to local time.
因为这是你获得的价值,它建议在路径参数中描述的文件很可能不存在 - 所以你应该检查文件的值
并记住,如果它是一个相对的文件名,它可能不是相对于你期望的目录。
As that's the value you're getting, it suggests the file described in the path parameter quite possibly doesn't exist - so you should check the value of file
and bear in mind that if it's a relative filename, it might not be relative to the directory you're expecting.
这篇关于Get Last Write Time返回一个奇怪的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!