Subtract time interval from DateTimeOffset, and yields a new date and time in CSharp

Description

The following code shows how to subtract time interval from DateTimeOffset, and yields a new date and time.

Example


//from w  w  w .j  a v  a  2  s.c  om

using System;
public class MainClass{
  public static void Main(String[] argv){  
    DateTimeOffset offsetDate = new DateTimeOffset(2014, 12, 3, 11, 30, 0, 
                                   new TimeSpan(-8, 0, 0)); 
    TimeSpan duration = new TimeSpan(7, 18, 0, 0);
    Console.WriteLine(offsetDate - duration); 

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var