C# DateTime FromFileTime

Description

DateTime FromFileTime converts the specified Windows file time to an equivalent local time.

Syntax

DateTime.FromFileTime has the following syntax.


public static DateTime FromFileTime(
  long fileTime
)

Parameters

DateTime.FromFileTime has the following parameters.

  • fileTime - A Windows file time expressed in ticks.

Returns

DateTime.FromFileTime method returns An object that represents the local time equivalent of the date and time represented by the fileTime parameter.

Example

You can determine whether a particular date and time value may be subject to modification by passing it to the TimeZoneInfo.IsInvalidTime method, as the example illustrates.


using System;/* w ww . ja  va  2 s .  c  o m*/

public class Example
{
   public static void Main()
   {
      DateTime date1 = new DateTime(2010, 3, 14, 2, 30, 00);
      Console.WriteLine("Invalid Time: {0}", 
                        TimeZoneInfo.Local.IsInvalidTime(date1));
      long ft = date1.ToFileTime();
      DateTime date2 = DateTime.FromFileTime(ft);
      Console.WriteLine("{0} -> {1}", date1, date2); 
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version