DateTimeOffset.EqualsExact(DateTimeOffset)方法用于确定当前的DateTimeOffset对象是否与指定的DateTimeOffset对象表示相同的时间并具有相同的偏移量。
用法: public bool EqualsExact (DateTimeOffset other);
Here, it takes the object to compare to the current DateTimeOffset object.
返回值:如果当前DateTimeOffset对象和其他对象具有相同的日期和时间值以及相同的Offset值,则此方法返回true;否则,此方法返回true。否则为假。
以下示例程序旨在说明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
参考:
相关用法
注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 DateTimeOffset.EqualsExact() Method in C#。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。