Get Last Write Time is returning a strange value

青春壹個敷衍的年華 提交于 2019-12-23 13:27:04

问题


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);

I output the value:

MessageBox.Show(lastMod.toString());

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.


回答1:


I suspect you're using the wrong file name. The documentation for GetLastWriteTime specifies:

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.



来源:https://stackoverflow.com/questions/20306688/get-last-write-time-is-returning-a-strange-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!