GetLastWriteTime 返回 12/31/1600 7:00:00 PM [英] GetLastWriteTime returning 12/31/1600 7:00:00 PM
问题描述
我正在使用以下代码将目录的修改日期时间写入标签
I am using the following code to write the Date Modified time of a Directory to a label
string selectedPath = comboBox1.SelectedItem.ToString();
DateTime lastdate = Directory.GetLastWriteTime(selectedPath);
datemodified.Text = lastdate.ToString();
它返回日期 12/31/1600 7:00:00 PM,我不知道它从哪里获取该日期.谁能帮我理解为什么它会返回那个日期以及我该如何解决它?我正在使用 .NET 3.5
It returns the date 12/31/1600 7:00:00 PM which I have no clue where it is getting that date from. Can anyone help me understand why it is returning that date and how I can fix it? I'm using .NET 3.5
推荐答案
来自 文档:
如果路径参数中描述的目录不存在,则此方法返回公元 1601 年 1 月 1 日午夜 12:00 的协调世界时 (UTC),调整为当地时间.
If the directory 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.
所以大概你的时区是 UTC-5(一月份),并且目录不存在......
So presumably your time zone is UTC-5 (in January), and the directory doesn't exist...
这篇关于GetLastWriteTime 返回 12/31/1600 7:00:00 PM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!