gpt4 book ai didi

c# - 使用 GetLastWriteTime 时出现不正确的年份

转载 作者:行者123 更新时间:2023-11-30 21:09:47 27 4
gpt4 key购买 nike

我有以下代码行:

<%= System.IO.File.GetLastWriteTime("~/Views/Home/Index.aspx").ToString("yyyy-MM-dd")  %> 

在资源管理器中,文件显示为在 1/2/2012 被修改。但是此代码输出 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.

Reference

根据您的时区进行调整后;这就是您获得 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com