DirectoryInfo.CreationTime returns strange date
.net-3.5, c#
Solution
I can shed some light on the "strange date".
Windows file times are based off of 1/1/1601.
A file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC). The system records file times when applications create, access, and write to files.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724290(v=vs.85).aspx
It would appear that your file system is reporting a 16 year offset to `DirectoryInfo` (which inherits from the `FileSystemInfo` class, which is calling `GetFileAttributesEx()`).
The .Net wrapper
public DateTime CreationTimeUtc
{
get{
long fileTime = (long)((ulong)this._data.ftCreationTimeHigh << 32 | (ulong)this._data.ftCreationTimeLow);
return DateTime.FromFileTimeUtc(fileTime);
}
}
`DateTime.FromFileTimeUtc` adds a value equal to 1/1/1601:
long ticks = fileTime + 504911232000000000L;
return new DateTime(ticks, DateTimeKind.Utc);
I can't find any significance to the offset (16 years). It seems too large to be DST errors or leap years, even accumulated over centuries.
I do think it is peculiar that both `CreationTime` and `CreationTimeUtc` return exactly the same date (unless your local time is the same as UTC).
Problem
I'm using DirectoryInfo.CreationTime to get the date when the directory is created however it returns strange date `{21/11/1617 0:00:00}` ``` var directoryInfo = new DirectoryInfo("C:\\testFolder"); var lastWriteTime = directoryInfo.LastWriteTime; // correct value var creationTime = directoryInfo.CreationTime; // Date = {21/11/1617 0:00:00} var creationTimeUtc = directoryInfo.CreationTimeUtc; // Date = {21/11/1617 0:00:00} ``` any idea? In Addition: The folder located in NAS share, some folders returns the correct value and some not I did the following tests: - Restart my machine and check that the data and time is set correctly - Run the application from another machine - recreate the application using .NET 4.0 VS2010 - Run the application from different OS windows 7 All returns the same value. however if i select folder properties the creation date is set to 2008. Is this a bug?