DateTimeOffset.EqualsExact(DateTimeOffset) Metoda

Definicja

Określa, czy bieżący DateTimeOffset obiekt reprezentuje ten sam czas i ma to samo przesunięcie co określony DateTimeOffset obiekt.

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

Parametry

other
DateTimeOffset

Obiekt do porównania z bieżącym DateTimeOffset obiektem.

Zwraca

Boolean

truejeśli bieżący obiekt i other ma tę samą wartość daty i godziny oraz tę samą Offset wartość; w przeciwnym razie false.DateTimeOffset

Przykłady

Poniższy przykład ilustruje użycie EqualsExact metody do porównywania podobnych DateTimeOffset obiektów.

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

Uwagi

Ponieważ wiele stref czasowych współdzieli jedno przesunięcie, wartość zwracana true nie gwarantuje, że bieżący i other obiekt reprezentuje czasy w tej samej strefie czasowej.

EqualsExact W przeciwieństwie do metody przeciążenia Equals metody określają tylko, czy dwie DateTimeOffset wartości reprezentują pojedynczy punkt w czasie. Nie wskazują one, że dwie wartości mają taką samą datę i godzinę, jak również to samo przesunięcie.

Dotyczy

Zobacz też