本文整理匯總了C#中System.DateTime.Equals方法的典型用法代碼示例。如果您正苦於以下問題:C# DateTime.Equals方法的具體用法?C# DateTime.Equals怎麽用?C# DateTime.Equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.DateTime
的用法示例。
在下文中一共展示了DateTime.Equals方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1:
System.DateTime today1 =
new System.DateTime(System.DateTime.Today.Ticks);
System.DateTime today2 =
new System.DateTime(System.DateTime.Today.Ticks);
System.DateTime tomorrow =
new System.DateTime(
System.DateTime.Today.AddDays(1).Ticks);
// todayEqualsToday gets true.
bool todayEqualsToday = System.DateTime.Equals(today1, today2);
// todayEqualsTomorrow gets false.
bool todayEqualsTomorrow = System.DateTime.Equals(today1, tomorrow);
示例2: Main
//引入命名空間
using System;
public class Application
{
public static void Main()
{
// Create some DateTime objects.
DateTime one = DateTime.UtcNow;
DateTime two = DateTime.Now;
DateTime three = one;
// Compare the DateTime objects and display the results.
bool result = one.Equals(two);
Console.WriteLine("The result of comparing DateTime object one and two is: {0}.", result);
result = one.Equals(three);
Console.WriteLine("The result of comparing DateTime object one and three is: {0}.", result);
}
}
// This code example displays the following:
//
// The result of comparing DateTime object one and two is: False.
// The result of comparing DateTime object one and three is: True.
示例3: DateTime.Equals(DateTime dt)
//引入命名空間
using System;
class MainClass {
public static void Main() {
DateTime myDateTime3 = new DateTime(2004, 1, 13);
DateTime myDateTime4 = new DateTime(2004, 1, 14);
bool boolResult = DateTime.Equals(myDateTime3, myDateTime4);
Console.WriteLine("DateTime.Equals(myDateTime3,myDateTime4) = " + boolResult);
boolResult = myDateTime3.Equals(myDateTime4);
Console.WriteLine("myDateTime3.Equals(myDateTime4) is " + boolResult);
}
}
示例4: DateTime.Equals(DateTime first, DateTime second)
//引入命名空間
using System;
class MainClass
{
public static void Main()
{
DateTime myDateTime3 = new DateTime(2004, 1, 13);
DateTime myDateTime4 = new DateTime(2004, 1, 14);
Console.WriteLine("myDateTime3 = " + myDateTime3);
Console.WriteLine("myDateTime4 = " + myDateTime4);
bool boolResult = DateTime.Equals(myDateTime3, myDateTime4);
Console.WriteLine("DateTime.Equals(myDateTime3, myDateTime4) = " + boolResult);
boolResult = myDateTime3.Equals(myDateTime4);
Console.WriteLine("myDateTime3.Equals(myDateTime4) is " + boolResult);
}
}