DateTimeOffset.EqualsExact(DateTimeOffset)方法用于确定当前的DateTimeOffset对象是否与指定的DateTimeOffset对象表示相同的时间并具有相同的偏移量。
Syntax: public bool EqualsExact (DateTimeOffset other);
Here, it takes the object to compare to the current DateTimeOffset object.
Return Value: This method returns true if the current DateTimeOffset object and other have the same date and time value and the same Offset value; otherwise, false.
下面的程序说明了DateTimeOffset.EqualsExact(DateTimeOffset)方法的用法:
范例1:
// C# program to demonstrate the
// DateTimeOffset.EqualsExact(DateTimeOffset)
// Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// creating object of DateTimeOffset
DateTimeOffset offset1 = new DateTimeOffset(2007,
6, 1, 7, 55, 0, new TimeSpan(-5, 0, 0));
// creating object of DateTimeOffset
DateTimeOffset offset2 = new DateTimeOffset(2006,
6, 1, 7, 55, 0, new TimeSpan(-5, 0, 0));
// comparing two offset1 and offset2
// instance using EqualsExact() method
bool value = offset1.EqualsExact(offset2);
if (value)
{
Console.Write("offset1 is same as offset2 ");
}
else
{
Console.Write("offset1 is not same as offset2");
}
}
}
输出:
offset1 is not same as offset2
范例2:
// C# program to demonstrate the
// DateTimeOffset.EqualsExact(DateTimeOffset)
// Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// creating object of DateTimeOffset
DateTimeOffset offset1 = new DateTimeOffset(2006,
6, 1, 7, 55, 0, new TimeSpan(-5, 0, 0));
// creating object of DateTimeOffset
DateTimeOffset offset2 = new DateTimeOffset(2006,
6, 1, 7, 55, 0, new TimeSpan(-5, 0, 0));
// comparing two offset1 and offset2
// instance using EqualsExact() method
bool value = offset1.EqualsExact(offset2);
if (value)
{
Console.Write("offset1 is same as offset2 ");
}
else
{
Console.Write("offset1 is not same as offset2");
}
}
}
输出:
offset1 is same as offset2
参考:
- https://docs.microsoft.com/zh-cn/dotnet/api/system.datetimeoffset.equalsexact?view=netframework-4.7.2