DateTimeOffset.Subtraction DateTimeOffset.Subtraction DateTimeOffset.Subtraction DateTimeOffset.Subtraction Operator

定義

オーバーロード

Subtraction(DateTimeOffset, DateTimeOffset) Subtraction(DateTimeOffset, DateTimeOffset) Subtraction(DateTimeOffset, DateTimeOffset) Subtraction(DateTimeOffset, DateTimeOffset)

一方の DateTimeOffset オブジェクトをもう一方のオブジェクトから減算し、時間間隔を生成します。Subtracts one DateTimeOffset object from another and yields a time interval.

Subtraction(DateTimeOffset, TimeSpan) Subtraction(DateTimeOffset, TimeSpan) Subtraction(DateTimeOffset, TimeSpan)

指定した日付と時刻から指定した時間間隔を減算して、新しい日付と時刻を作成します。Subtracts a specified time interval from a specified date and time, and yields a new date and time.

Subtraction(DateTimeOffset, DateTimeOffset) Subtraction(DateTimeOffset, DateTimeOffset) Subtraction(DateTimeOffset, DateTimeOffset) Subtraction(DateTimeOffset, DateTimeOffset)

一方の DateTimeOffset オブジェクトをもう一方のオブジェクトから減算し、時間間隔を生成します。Subtracts one DateTimeOffset object from another and yields a time interval.

public:
 static TimeSpan operator -(DateTimeOffset left, DateTimeOffset right);
public static TimeSpan operator - (DateTimeOffset left, DateTimeOffset right);
static member ( - ) : DateTimeOffset * DateTimeOffset -> TimeSpan
Public Shared Operator - (left As DateTimeOffset, right As DateTimeOffset) As TimeSpan

パラメーター

戻り値

leftright の差を表すオブジェクト。An object that represents the difference between left and right.

注釈

Subtractionメソッド定義の減算演算DateTimeOffsetオブジェクト。The Subtraction method defines the subtraction operation for DateTimeOffset objects. 次のようなコードが有効にします。It enables code such as the following:

DateTimeOffset firstDate = new DateTimeOffset(2008, 3, 25, 18, 0, 0, 
                                              new TimeSpan(-7, 0, 0));
DateTimeOffset secondDate = new DateTimeOffset(2008, 3, 25, 18, 0, 0, 
                                               new TimeSpan(-5, 0, 0));
DateTimeOffset thirdDate = new DateTimeOffset(2008, 2, 28, 9, 0, 0, 
                                              new TimeSpan(-7, 0, 0));
TimeSpan difference;

difference = firstDate - secondDate;
Console.WriteLine("({0}) - ({1}): {2} days, {3}:{4:d2}", 
                  firstDate.ToString(), 
                  secondDate.ToString(), 
                  difference.Days, 
                  difference.Hours, 
                  difference.Minutes);      

difference = firstDate - thirdDate;
Console.WriteLine("({0}) - ({1}): {2} days, {3}:{4:d2}", 
                  firstDate.ToString(), 
                  secondDate.ToString(), 
                  difference.Days, 
                  difference.Hours, 
                  difference.Minutes); 
// The example produces the following output:
//    (3/25/2008 6:00:00 PM -07:00) - (3/25/2008 6:00:00 PM -05:00): 0 days, 2:00
//    (3/25/2008 6:00:00 PM -07:00) - (3/25/2008 6:00:00 PM -05:00): 26 days, 9:00                                 
Dim firstDate As New DateTimeOffset(#3/25/2008 6:00PM#, _
                                    New TimeSpan(-7, 0, 0))
Dim secondDate As New DateTimeOffset(#3/25/2008 6:00PM#, _
                                     New TimeSpan(-5, 0, 0))
Dim thirdDate As New DateTimeOffset(#2/28/2008 9:00AM#, _
                                    New TimeSpan(-7, 0, 0))
Dim difference As TimeSpan

difference = firstDate - secondDate
Console.WriteLine("({0}) - ({1}): {2} days, {3}:{4:d2}", _
                  firstDate.ToString(), _
                  secondDate.ToString(), _
                  difference.Days, _
                  difference.Hours, _
                  difference.Minutes)      
difference = firstDate - thirdDate
Console.WriteLine("({0}) - ({1}): {2} days, {3}:{4:d2}", _
                  firstDate.ToString(), _
                  secondDate.ToString(), _
                  difference.Days, _
                  difference.Hours, _
                  difference.Minutes) 
' The example produces the following output:
'    (3/25/2008 6:00:00 PM -07:00) - (3/25/2008 6:00:00 PM -05:00): 0 days, 2:00
'    (3/25/2008 6:00:00 PM -07:00) - (3/25/2008 6:00:00 PM -05:00): 26 days, 9:00                                 

カスタム演算子と演算子のオーバー ロードをサポートしない言語を呼び出すことができます、DateTimeOffset.Subtract(DateTimeOffset)メソッド代わりにします。Languages that do not support custom operators and operator overloading can call the DateTimeOffset.Subtract(DateTimeOffset) method instead.

この演算子を同等のメソッドはDateTimeOffset.Subtract(TimeSpan)します。The equivalent method for this operator is DateTimeOffset.Subtract(TimeSpan).

こちらもご覧ください

Subtraction(DateTimeOffset, TimeSpan) Subtraction(DateTimeOffset, TimeSpan) Subtraction(DateTimeOffset, TimeSpan)

指定した日付と時刻から指定した時間間隔を減算して、新しい日付と時刻を作成します。Subtracts a specified time interval from a specified date and time, and yields a new date and time.

public:
 static DateTimeOffset operator -(DateTimeOffset dateTimeTz, TimeSpan timeSpan);
public static DateTimeOffset operator - (DateTimeOffset dateTimeTz, TimeSpan timeSpan);
static member ( - ) : DateTimeOffset * TimeSpan -> DateTimeOffset

パラメーター

dateTimeOffset
DateTimeOffset DateTimeOffset DateTimeOffset DateTimeOffset

減算される日時オブジェクト。The date and time object to subtract from.

timeSpan
TimeSpan TimeSpan TimeSpan TimeSpan

減算する時間間隔。The time interval to subtract.

戻り値

dateTimeOffset から timeSpan を減算した値と等しいオブジェクト。An object that is equal to the value of dateTimeOffset minus timeSpan.

例外

結果として返された DateTimeOffset 値が MinValue 未満であるか、MaxValue を超えています。The resulting DateTimeOffset value is less than MinValue or greater than MaxValue.

注釈

Subtractionメソッド定義の減算演算DateTimeOffsetオブジェクト。The Subtraction method defines the subtraction operation for DateTimeOffset objects. 次のようなコードが有効にします。It enables code such as the following:

DateTimeOffset offsetDate = new DateTimeOffset(2007, 12, 3, 11, 30, 0, 
                               new TimeSpan(-8, 0, 0)); 
TimeSpan duration = new TimeSpan(7, 18, 0, 0);
Console.WriteLine(offsetDate - duration);  // Displays 11/25/2007 5:30:00 PM -08:00
Dim offsetDate As New DateTimeOffset(#12/3/2007 11:30AM#, _
                               New TimeSpan(-8, 0, 0)) 
Dim duration As New TimeSpan(7, 18, 0, 0)
Console.WriteLine(offsetDate - duration)    ' Displays 11/25/2007 5:30:00 PM -08:00

カスタム演算子と演算子のオーバー ロードをサポートしない言語を呼び出すことができます、DateTimeOffset.Subtract(TimeSpan)メソッド代わりにします。Languages that do not support custom operators and operator overloading can call the DateTimeOffset.Subtract(TimeSpan) method instead.

この演算子を同等のメソッドはDateTimeOffset.Subtract(TimeSpan)します。The equivalent method for this operator is DateTimeOffset.Subtract(TimeSpan).

こちらもご覧ください

適用対象