GetLastWriteTime回到1600年12月31日下午7点00分00秒下午、GetLastWriteTime

2023-09-07 02:52:25 作者:岛是海上的疤

我使用下面的code编写修改目录的时间标签的日期

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

它返回的日期1600年12月31号晚上7:00:00点,我不知道在那里获得自该日起。谁能帮助我理解为什么它返回的日期,我怎么能解决这个问题?我使用.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

推荐答案

从文档:

如果在path参数中描述的目录不存在,午夜12:00这个方法返回,1月1日,公元1601(CE)协调世界时(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.

所以presumably时区为UTC-5(一月),以及目录不存在...

So presumably your time zone is UTC-5 (in January), and the directory doesn't exist...