📜  C#中的TimeSpan.FromTicks()方法

📅  最后修改于: 2021-05-29 19:06:54             🧑  作者: Mango

此方法用于获取表示指定时间的TimeSpan,其中指定以刻度为单位。

下面的程序说明了TimeSpan.FromTicks(Int64)方法的用法:

范例1:

// C# program to demonstrate the
// TimeSpan.FromTicks() Method
using System;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        TimeSpan interval = TimeSpan.FromTicks(1234);
        Console.WriteLine("The Timespan is : {0}",
                                       interval);
    }
}
输出:
The Timespan is : 00:00:00.0001234

范例2:

// C# program to demonstrate the
// TimeSpan.FromTicks() Method
using System;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        TimeSpan interval = TimeSpan.FromTicks(999999);
  
        Console.WriteLine("The Timespan is : {0}",
                                        interval);
    }
}
输出:
The Timespan is : 00:00:00.0999999

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.timespan.fromticks?view=netframework-4.7.2