DirectoryInfo.CreationTime returns a strange date

I use DirectoryInfo.CreationTime to get the catalog creation date however it returns a 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?

Additionally:

A shared NAS folder, some folders return the correct value, and some do not. I performed the following tests:

  • Reboot the machine and make sure that the data and time are set correctly.
  • Launch the application from another computer.
  • recreate an application using .NET 4.0 VS2010
  • Launching an application from different windows of OS 7

Everything returns the same value. however, if I select the folder properties, the creation date will be set to 2008. This is mistake?

+4
source share
2 answers

I can shed light on a "strange date."

Windows file time is based on 1/1/1601.

File time is a 64-bit value that represents the number of 100 nanosecond intervals elapsed from 12:00 AM January 1, 1601 Coordinated Universal Time (UTC). The system records the file time when applications create, access and write files.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724290(v=vs.85).aspx

It looks like your file system is reporting a 16-year bias towards DirectoryInfo (which inherits from the FileSystemInfo class that calls GetFileAttributesEx() ).

.Net Shell

 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 not find any value for the bias (16 years). Seems too big to be DST bugs or leap years, even accumulated over the centuries.

I find it strange that both CreationTime and CreationTimeUtc return exactly the same date (if your local time does not coincide with UTC).

+3
source

The msdn documentation on CreationTime talks about a problem that might cause this

Check out the Notes section of this link below.

http://msdn.microsoft.com/en-IN/library/system.io.filesysteminfo.creationtime.aspx

This may be a cached value that is not updated. You can use the Refresh method for this. As pointed out in the comments, some older platforms can also cause problems.

0
source

All Articles