Compartilhar via


DateTimeOffset.EqualsExact(DateTimeOffset) Método

Definição

Determina se o objeto DateTimeOffset atual representa a mesma hora e tem o mesmo deslocamento que um objeto DateTimeOffset especificado.

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

Parâmetros

other
DateTimeOffset

O objeto a ser comparado com o objeto DateTimeOffset atual.

Retornos

Boolean

true se o objeto DateTimeOffset atual e other têm o mesmo valor de data e hora e o mesmo valor Offset; caso contrário, false.

Exemplos

O exemplo a seguir ilustra o uso do EqualsExact método para comparar objetos semelhantes DateTimeOffset .

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

Comentários

Como vários fusos horários compartilham um único deslocamento, um valor retornado true não garante que o atual e o other objeto representem tempos no mesmo fuso horário.

Ao contrário do EqualsExact método, as sobrecargas do Equals método determinam apenas se dois DateTimeOffset valores representam um único ponto no tempo. Eles não indicam que dois valores têm a mesma data e hora, bem como o mesmo deslocamento.

Aplica-se a

Confira também