本文整理匯總了C#中System.DateTime.FromFileTime方法的典型用法代碼示例。如果您正苦於以下問題:C# DateTime.FromFileTime方法的具體用法?C# DateTime.FromFileTime怎麽用?C# DateTime.FromFileTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.DateTime
的用法示例。
在下文中一共展示了DateTime.FromFileTime方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: FileAge
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;
}
}
示例2: Main
//引入命名空間
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);
}
}
輸出:
Invalid Time: True 3/14/2010 2:30:00 AM -> 3/14/2010 3:30:00 AM
示例3: Main
//引入命名空間
using System;
class MainClass
{
public static void Main()
{
DateTime myDateTime10 = new DateTime(2004, 1, 15, 23, 2, 5);
long myFileTime = myDateTime10.ToFileTime();
DateTime myDateTime11 = DateTime.FromFileTime(myFileTime);
Console.WriteLine("DateTime.FromFileTime() = " + myDateTime11);
}
}