This method is used to get a TimeSpan that represents a specified number of seconds, accurate to the nearest millisecond.
Syntax: public static TimeSpan FromSeconds (double value);
Parameter:
value: This parameter specifies the number of seconds, accurate to the nearest millisecond..Return Value: It returns a new TimeSpan object that represents the value.
Exceptions:
- OverflowException: When the given double value is smaller than smallest possible value or greater than the largest possible value or the value is PositiveInfinity or is NegativeInfinity.
- ArgumentException: When the value is NaN.
Below programs illustrate the use of TimeSpan.FromSeconds(Double) Method:
Example 1:
// C# program to demonstrate the // TimeSpan.FromSeconds(Double) // Method using System; class GFG { // Main Method public static void Main() { try { TimeSpan interval = TimeSpan.FromSeconds(0.43459); Console.WriteLine("The Timespan is : {0}", interval); } catch (OverflowException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } } |
The Timespan is : 00:00:00.4350000
Example 2: For Overflow Exception
// C# program to demonstrate the // TimeSpan.FromSeconds(Double) // Method using System; class GFG { // Main Method public static void Main() { try { TimeSpan interval = TimeSpan.FromSeconds(Double.NegativeInfinity); Console.WriteLine("The Timespan is : {0}", interval); } catch (OverflowException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } } |
Exception Thrown: System.OverflowException
Reference:
Recommended Posts:
- Difference between Method Overriding and Method Hiding in C#
- Main Method in C#
- Stack.Pop() Method in C#
- C# | Math.Max() Method
- DateTime.Add() Method in C#
- C# | Math.Abs() Method | Set - 2
- C# | Math.Abs() Method | Set - 1
- C# | Method Parameters
- C# | Math.Log() Method
- C# | Method Overriding
- C# | IsNullOrEmpty() Method
- C# | Math.Min() Method
- Stack.Contains() Method in C#
- Queue.Contains() Method in C#
- C# | String.Contains() Method
- C# | Math.Sin() Method
- C# | Math.Cos() Method
- C# | Math.Tan() Method
- C# | CompareOrdinal() Method
- C# | Trim() Method
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.
Improved By : shubham_singh

