开发者

FileInfo displaying a peculiar date

Why does the following display 12/31/1600 ???

Imports System.IO

Module 开发者_StackOverflowModule1

Sub Main()
    Dim fi As New FileInfo("DocFiles\phillips_phone_number.txt")
    Console.WriteLine(fi.FullName)
    Console.WriteLine(fi.LastAccessTime.ToShortDateString)
    Console.ReadKey()
End Sub

End Module


It seems that code is not able to find the file, see the documentation for the GetLastAccessTime function in the SDK http://msdn.microsoft.com/en-us/library/system.io.file.getlastaccesstime.aspx

It states,

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.


You did not specify the time you are seeing, only the date, but I suspect it is 23:00:00. If you use Console.WriteLine(fi.LastAccessTime), you will likely see it print -36000000000.

The last-access-timestamp of the file is being returned as 0 either because, as Sijin pointed out, the path is invalid, or because you have disabled the last-access update on an NTFS volume, or because you are using Vista or higher in which it is disabled by default.

In any case, because Windows uses January 1, 1601 as its epoch base, a date of 0 would return 00:00:00 1601-01-01.

Now why are you seeing it as December 31, 1600 instead? Simple: timezones. Your profile has no biographical information, but your name and the Latin quote in your biography section make it not unreasonable to guess that you may be living somewhere around Spain, which is in the timezone UTC+01:00. In this case, when the timestamp is adjusted to local time, it would take the time (0) as the base, and subtract one hour to convert it to your timezone. Thus, you get the value -36000000000 which is 23:00:00 1600-12-31.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜