Condividi tramite


DateTimeOffset.Subtract Method (DateTimeOffset)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Subtracts a DateTimeOffset value that represents a specific date and time from the current DateTimeOffset object.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Function Subtract ( _
    value As DateTimeOffset _
) As TimeSpan
public TimeSpan Subtract(
    DateTimeOffset value
)

Parameters

Return Value

Type: System.TimeSpan
An object that specifies the interval between the two DateTimeOffset objects.

Remarks

This method converts both DateTimeOffset objects to Coordinated Universal Time (UTC) before calculating the time interval that separates them. This removes any effect that different offsets from UTC may have on the comparison.

NoteNote:

For languages that support custom operators, you can also perform date and time subtraction by using the subtraction operator. For details, see the Subtraction method.

Because neither the current DateTimeOffset object nor the value parameter represent the date and time in a specific time zone, the Subtract(DateTimeOffset) method does not consider a particular time zone's adjustment rules when it subtracts dates and times.

Examples

The following example illustrates subtraction that uses the Subtract(DateTimeOffset) method.

Dim offsetDate As New DateTimeOffset(#12/3/2007 11:30:00 AM#, _
                               New TimeSpan(-8, 0, 0))
Dim duration As New TimeSpan(7, 18, 0, 0)
outputBlock.Text += offsetDate.Subtract(duration).ToString() + vbCrLf    ' Displays 11/25/2007 5:30:00 PM -08:00
DateTimeOffset offsetDate = new DateTimeOffset(2007, 12, 3, 11, 30, 0,
                               new TimeSpan(-8, 0, 0));
TimeSpan duration = new TimeSpan(7, 18, 0, 0);
outputBlock.Text += offsetDate.Subtract(duration).ToString() + "\n";  // Displays 11/25/2007 5:30:00 PM -08:00

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.