Create DateTime from file time in CSharp

Description

The following code shows how to create DateTime from file time.

Example


//from w ww  . j av  a 2  s . com
using System;

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 »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var