DateTimeOffset.EqualsExact(DateTimeOffset) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Determines whether the current DateTimeOffset object represents the same time and has the same offset as a specified DateTimeOffset object.
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
The object to compare to the current DateTimeOffset object.
true
if the current DateTimeOffset object and other
have the same date and time value and the same Offset value; otherwise, false
.
The following example illustrates the use of the EqualsExact method to compare similar DateTimeOffset objects.
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
Because multiple time zones share a single offset, a return value of true
does not guarantee that the current and the other
object represent times in the same time zone.
Unlike the EqualsExact method, the overloads of the Equals method determine only whether two DateTimeOffset values represent a single point in time. They do not indicate that two values have the same date and time as well as the same offset.
Product | Versions |
---|---|
.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, 8, 9 |
.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, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: