DateTimeOffset.EqualsExact(DateTimeOffset) メソッド

定義

現在の DateTimeOffset オブジェクトが、指定された DateTimeOffset オブジェクトと同じ特定の時点を表しており、かつ、同じオフセットを持つかどうかを判断します。

public:
 bool EqualsExact(DateTimeOffset other);
public bool EqualsExact (DateTimeOffset other);
member this.EqualsExact : DateTimeOffset -> bool
Public Function EqualsExact (other As DateTimeOffset) As Boolean

パラメーター

other
DateTimeOffset

現在の DateTimeOffset オブジェクトと比較するオブジェクト。

戻り値

Boolean

現在の DateTimeOffset オブジェクトと other が同じ日時の値を持ち、かつ同じ Offset 値を持つ場合は true。それ以外の場合は false

次の例は、メソッドを使用して同様DateTimeOffsetEqualsExactオブジェクトを比較する方法を示しています。

DateTimeOffset instanceTime = new DateTimeOffset(2007, 10, 31, 0, 0, 0,
                              DateTimeOffset.Now.Offset);

DateTimeOffset otherTime = instanceTime;
Console.WriteLine("{0} = {1}: {2}",
                  instanceTime, otherTime,
                  instanceTime.EqualsExact(otherTime));

otherTime = new DateTimeOffset(instanceTime.DateTime,
            TimeSpan.FromHours(instanceTime.Offset.Hours + 1));
Console.WriteLine("{0} = {1}: {2}",
                  instanceTime, otherTime,
                  instanceTime.EqualsExact(otherTime));

otherTime = new DateTimeOffset(instanceTime.DateTime + TimeSpan.FromHours(1),
                TimeSpan.FromHours(instanceTime.Offset.Hours + 1));
Console.WriteLine("{0} = {1}: {2}",
                  instanceTime, otherTime,
                  instanceTime.EqualsExact(otherTime));
// The example produces the following output:
//       10/31/2007 12:00:00 AM -07:00 = 10/31/2007 12:00:00 AM -07:00: True
//       10/31/2007 12:00:00 AM -07:00 = 10/31/2007 12:00:00 AM -06:00: False
//       10/31/2007 12:00:00 AM -07:00 = 10/31/2007 1:00:00 AM -06:00: False
let instanceTime = DateTimeOffset(2007, 10, 31, 0, 0, 0, DateTimeOffset.Now.Offset)

let otherTime = instanceTime
printfn $"{instanceTime} = {otherTime}: {instanceTime.EqualsExact otherTime}"

let otherTime = DateTimeOffset(instanceTime.DateTime, TimeSpan.FromHours(instanceTime.Offset.Hours + 1 |> float))
printfn $"{instanceTime} = {otherTime}: {instanceTime.EqualsExact otherTime}"

let otherTime = DateTimeOffset(instanceTime.DateTime + TimeSpan.FromHours 1, TimeSpan.FromHours(instanceTime.Offset.Hours + 1 |> float))
printfn $"{instanceTime} = {otherTime}: {instanceTime.EqualsExact otherTime}"

// The example produces the following output:
//       10/31/2007 12:00:00 AM -07:00 = 10/31/2007 12:00:00 AM -07:00: True
//       10/31/2007 12:00:00 AM -07:00 = 10/31/2007 12:00:00 AM -06:00: False
//       10/31/2007 12:00:00 AM -07:00 = 10/31/2007 1:00:00 AM -06:00: False
Dim instanceTime As New DateTimeOffset(#10/31/2007 12:00AM#, _
                                       DateTimeOffset.Now.Offset)

Dim otherTime As DateTimeOffset = instanceTime
Console.WriteLine("{0} = {1}: {2}", _
                  instanceTime, otherTime, _
                  instanceTime.EqualsExact(otherTime))
                  
otherTime = New DateTimeOffset(instanceTime.DateTime, _
                               TimeSpan.FromHours(instanceTime.Offset.Hours + 1))
Console.WriteLine("{0} = {1}: {2}", _
                  instanceTime, otherTime, _
                  instanceTime.EqualsExact(otherTime))
                  
otherTime = New DateTimeOffset(instanceTime.DateTime + TimeSpan.FromHours(1), _
                                TimeSpan.FromHours(instanceTime.Offset.Hours + 1))
Console.WriteLine("{0} = {1}: {2}", _
                  instanceTime, otherTime, _
                  instanceTime.EqualsExact(otherTime))
' The example produces the following output:
'       10/31/2007 12:00:00 AM -07:00 = 10/31/2007 12:00:00 AM -07:00: True
'       10/31/2007 12:00:00 AM -07:00 = 10/31/2007 12:00:00 AM -06:00: False
'       10/31/2007 12:00:00 AM -07:00 = 10/31/2007 1:00:00 AM -06:00: False

注釈

複数のタイム ゾーンが 1 つのオフセットを共有するため、戻り値が true 現在とオブジェクトが other 同じタイム ゾーン内の時刻を表すという保証はありません。

EqualsExactメソッドとは異なり、メソッドのEqualsオーバーロードは、2 つのDateTimeOffset値が 1 つの時点を表すかどうかを判断するだけです。 これらは、2 つの値が同じ日付と時刻と同じオフセットを持っていることを示すものではありません。

適用対象

こちらもご覧ください