DateTimeOffset.EqualsExact(DateTimeOffset) Metodo
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Determina se l'oggetto DateTimeOffset corrente rappresenta la stessa ora e ha lo stesso offset di un oggetto DateTimeOffset specificato.
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
Oggetto da confrontare con l'oggetto DateTimeOffset corrente.
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
.
Nell'esempio seguente viene illustrato l'uso del EqualsExact metodo per confrontare oggetti simili 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
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.
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 |