C# TimeSpan Add

Description

TimeSpan Add returns a new TimeSpan object whose value is the sum of the specified TimeSpan object and this instance.

Syntax

TimeSpan.Add has the following syntax.


public TimeSpan Add(
  TimeSpan ts
)

Parameters

TimeSpan.Add has the following parameters.

  • ts - The time interval to add.

Returns

TimeSpan.Add method returns A new object that represents the value of this instance plus the value of ts.

Example

The following example calls the Add method to add time intervals to a base TimeSpan value.


/*from  w  w  w .j  a v a  2  s.c  o m*/
using System;

public class Example
{
   public static void Main()
   {
      TimeSpan baseTimeSpan = new TimeSpan(1, 12, 15, 16);
      TimeSpan interval = TimeSpan.FromDays(1.5);
      Console.WriteLine(baseTimeSpan.Add(interval));
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version