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
public static DateTime FromFileTime(
 long fileTime
public: static DateTime FromFileTime(
 __int64 fileTime
public static function FromFileTime(
   fileTime : long
) : DateTime;


A Windows file time.

Return Value

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


Exception Type Condition
ArgumentOutOfRangeException fileTime is not valid.


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).


[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

      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.
   End Try
End Function

public System.TimeSpan FileAge(long fileCreationTime) {

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

System::TimeSpan FileAge(long fileCreationTime) {

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

[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.


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

© 2014 Microsoft