TimeSpan.FromMinutes() Method in C#

This method is used to get a TimeSpan that represents a specified number of minutes, where the specification is accurate to the nearest millisecond.

Syntax: public static TimeSpan FromMinutes (double value);

Paramater:
value: This parameter specifies the number of minutes, accurate to the nearest millisecond.



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

Exceptions:

  • OverflowException: If the given double value is smaller than the smallest possible value or greater than the largest possible value or the value is PositiveInfinity or is NegativeInfinity.
  • ArgumentException: If the value is NaN.

Below programs illustrate the use of TimeSpan.FromMinutes(Double)Method:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// TimeSpan.FromMinutes(Double) Method
using System;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        try {
  
            TimeSpan interval = TimeSpan.FromMinutes(8.12345);
            Console.WriteLine("The Timespan is : {0}",
                                            interval);
        }
  
        catch (OverflowException e) 
        {
            Console.Write("Exception Thrown: ");
            Console.Write("{0}", e.GetType(), e.Message);
        }
    }
}

chevron_right


Output:

The Timespan is : 00:08:07.4070000

Example 2: For Overflow Exception

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// TimeSpan.FromMinutes(Double) Method
using System;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        try {
  
            TimeSpan interval = 
               TimeSpan.FromMinutes(Double.PositiveInfinity);
  
            Console.WriteLine("The Timespan is : {0}",
                                            interval);
        }
  
        catch (OverflowException e) 
        {
            Console.Write("Exception Thrown: ");
            Console.Write("{0}", e.GetType(), e.Message);
        }
    }
}

chevron_right


Output:

Exception Thrown: System.OverflowException

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 :

1


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