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#。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。