Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DateTime.FromFileTime Method

Returns a DateTime equivalent to the specified operating system file timestamp.

[Visual Basic]
Public Shared Function FromFileTime( _
   ByVal fileTime As Long _
) As DateTime
[C#]
public static DateTime FromFileTime(
 long fileTime
);
[C++]
public: static DateTime FromFileTime(
 __int64 fileTime
);
[JScript]
public static function FromFileTime(
   fileTime : long
) : DateTime;

Parameters

fileTime
A Windows file time.

Return Value

A DateTime value representing the date and time of fileTime, adjusted to local time.

Exceptions

Exception Type Condition
ArgumentOutOfRangeException fileTime is not valid.

Remarks

fileTime is a 64-bit signed integer value representing a Windows file timestamp. The timestamp is the number of 100-nanosecond intervals that have elapsed since January 1, 1601 A.D. (C.E.) 12:00 A.M. coordinated universal time (UTC).

Example

[Visual Basic, C#, C++] The following sample demonstrates the FromFileTime method.

[Visual Basic] 
Public Function FileAge(ByVal fileCreationTime As Long) As System.TimeSpan

   Dim now As System.DateTime
   now = System.DateTime.Now

   Try
      Dim fCreationTime As System.DateTime
      Dim fAge As System.TimeSpan
      fCreationTime = System.DateTime.FromFileTime(fileCreationTime)
      fAge = now.Subtract(fCreationTime)
      Return fAge
   Catch exp As ArgumentOutOfRangeException
      ' fileCreationTime is not valid, so re-throw the exception.
      Throw
   End Try
End Function

[C#] 
public System.TimeSpan FileAge(long fileCreationTime) {

    System.DateTime now = System.DateTime.Now;
    try {
        System.DateTime fCreationTime = 
            System.DateTime.FromFileTime(fileCreationTime);
        System.TimeSpan fileAge = now.Subtract(fCreationTime);
        return fileAge;                
    } 
    catch (ArgumentOutOfRangeException) {
        // fileCreationTime is not valid, so re-throw the exception.
        throw;
    }
}

[C++] 
System::TimeSpan FileAge(long fileCreationTime) {

   System::DateTime now = System::DateTime::Now;
   try {
      System::DateTime fCreationTime =
         System::DateTime::FromFileTime(fileCreationTime);
      System::TimeSpan fileAge = now.Subtract(fCreationTime);
      return fileAge;
   } catch (ArgumentOutOfRangeException*) {
      // fileCreationTime is not valid, so re-throw the exception.
      throw;
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DateTime Structure | DateTime Members | System Namespace | ToUniversalTime | GetUtcOffset

Show:
© 2014 Microsoft