當前位置: 首頁>>代碼示例>>C#>>正文


C# DateTime.Equals方法代碼示例

本文整理匯總了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);
開發者ID:.NET開發者,項目名稱:System,代碼行數:13,代碼來源:DateTime.Equals

示例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.
開發者ID:.NET開發者,項目名稱:System,代碼行數:29,代碼來源:DateTime.Equals

示例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);

    }
}
開發者ID:C#程序員,項目名稱:System,代碼行數:16,代碼來源:DateTime.Equals

示例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);
  }

}
開發者ID:C#程序員,項目名稱:System,代碼行數:20,代碼來源:DateTime.Equals


注:本文中的System.DateTime.Equals方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。