我有以下代码行:
<%= System.IO.File.GetLastWriteTime("~/Views/Home/Index.aspx").ToString("yyyy-MM-dd") %>
在资源管理器中,该文件显示为于 2012 年 1 月 2 日修改。但是此代码输出 1600-01-02。
最佳答案
您看到这种情况的原因是:
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.
调整到您的时区后;这就是您获得 1600-01-02
的原因。
我不相信 GetLastWriteTime
理解虚拟路径。它正在等待物理路径。尝试:
<%= System.IO.File.GetLastWriteTime(Server.MapPath("~/Views/Home/Index.aspx")).ToString("yyyy-MM-dd") %>
您可以使用Server.MapPath
将虚拟路径映射到物理路径。
关于c# - 使用 GetLastWriteTime 时显示不正确的年份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8852615/