Skip to content
Related Articles

Related Articles

TimeSpan.FromTicks() Method in C#

Improve Article
Save Article
Like Article
  • Last Updated : 30 Sep, 2019

This method is used to get a TimeSpan that represents a specified time, where the specification is in units of ticks.

Syntax: public static TimeSpan FromTicks (long value);

Parameter:
value: This parameter specifies the number of ticks that represent a time.

Return Value: It returns a new TimeSpan object that represents the value.

Below programs illustrate the use of TimeSpan.FromTicks(Int64) Method:

Example 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);
    }
}
Output:
The Timespan is : 00:00:00.0001234

Example 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);
    }
}
Output:
The Timespan is : 00:00:00.0999999

Reference:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!