This method is used to return a new DateTime that adds the specified number of seconds to the value of this instance.
public DateTime AddSeconds (double value);
Here, value is a number of whole and fractional seconds. The value parameter can be negative or positive.
Return Value: This method returns an object whose value is the sum of the date and time represented by this instance and the number of seconds represented by value.
Exception: This method will throw ArgumentOutOfRangeException if the resulting DateTime is less than MinValue or greater than MaxValue.
Below programs illustrate the use of the above-discussed method:
Original date: 09/07/2018 07:00:00 After Using Method: 09/07/2018 07:00:30
System.ArgumentOutOfRangeException: The added or subtracted value results in an un-representable DateTime.
Parameter name: value
- This method does not change the value of this DateTime. Instead, it returns a new DateTime whose value is the result of this operation.
- The fractional part of the value is the fractional part of a minute. For example, 7.5 is equivalent to 7 minutes, 30 seconds, 0 milliseconds, and 0 ticks.
- The value parameter is rounded to the nearest millisecond.
- Difference between Method Overriding and Method Hiding in C#
- C# | Trim() Method
- C# | Remove() Method
- Decimal.Add() Method in C#
- Anonymous Method in C#
- C# | Replace() Method
- C# | Insert() Method
- C# | CopyTo() Method
- C# | Math.Max() Method
- C# | Uri.IsHexEncoding() Method
- TimeSpan.Add() Method in C#
- Extension Method in C#
- C# | Uri.GetHashCode() Method
- C# | Uri.FromHex() Method
- C# | ToUpper() Method
- Stack.Contains() Method in C#
- C# | ToLower() Method
- C# | String.Contains() Method
- C# | Math.Sin() Method
- C# | Math.Cos() 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 email@example.com. 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.