TimeSpan.FromTicks() Method in C#

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

The Timespan is : 00:00:00.0001234

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

The Timespan is : 00:00:00.0999999

Reference:



My Personal Notes arrow_drop_up

Budding Web DeveloperKeen learnerAverage CoderDancer&Social Activist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.





Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.