DateTimeOffset.EqualsExact(DateTimeOffset) Metodo

Definizione

Determina se l'oggetto DateTimeOffset corrente rappresenta la stessa ora e ha lo stesso offset di un oggetto DateTimeOffset specificato.

C#
public bool EqualsExact (DateTimeOffset other);

Parametri

other
DateTimeOffset

Oggetto da confrontare con l'oggetto DateTimeOffset corrente.

Restituisce

Boolean

true se l'oggetto DateTimeOffset corrente e il parametro other presentano lo stesso valore di data e ora e lo stesso valore Offset; in caso contrario, false.

Esempio

Nell'esempio seguente viene illustrato l'uso del EqualsExact metodo per confrontare oggetti simili DateTimeOffset .

C#
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

Commenti

Poiché più fusi orari condividono un singolo offset, un valore restituito di true non garantisce che l'oggetto other e corrente rappresentino gli orari nello stesso fuso orario.

A differenza del EqualsExact metodo , gli overload del Equals metodo determinano solo se due DateTimeOffset valori rappresentano un singolo punto nel tempo. Non indicano che due valori hanno la stessa data e ora e lo stesso offset.

Si applica a

Prodotto Versioni
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Vedi anche