DateTime.Equality(DateTime, DateTime) 运算符

定义

确定 DateTime 的两个指定的实例是否相等。

public:
 static bool operator ==(DateTime d1, DateTime d2);
public static bool operator == (DateTime d1, DateTime d2);
static member ( = ) : DateTime * DateTime -> bool
Public Shared Operator == (d1 As DateTime, d2 As DateTime) As Boolean

参数

d1
DateTime

要比较的第一个对象。

d2
DateTime

要比较的第二个对象。

返回

Boolean

如果 trued1 表示同一日期和时间,则为 d2;否则为 false

示例

下面的示例演示了相等运算符。

System::DateTime april19( 2001, 4, 19 );
System::DateTime otherDate( 1991, 6, 5 );

// areEqual gets false.
bool areEqual = april19 == otherDate;

otherDate = DateTime( 2001, 4, 19 );
// areEqual gets true.
areEqual = april19 == otherDate;
System.DateTime april19 = new DateTime(2001, 4, 19);
System.DateTime otherDate = new DateTime(1991, 6, 5);

// areEqual gets false.
bool areEqual = april19 == otherDate;
    
otherDate = new DateTime(2001, 4, 19);
// areEqual gets true.
areEqual = april19 == otherDate;
Dim april19 As New DateTime(2001, 4, 19)
Dim otherDate As New DateTime(1991, 6, 5)

Dim areEqual As Boolean
' areEqual gets false.
areEqual = DateTime.op_Equality(april19, otherDate)

otherDate = New DateTime(2001, 4, 19)
' areEqual gets true.
areEqual = System.DateTime.op_Equality(april19, otherDate)

注解

Equality运算符通过比较两个 DateTime 值的计时周期数来确定这两个值是否相等。 在比较 DateTime 对象之前,请确保对象表示相同时区中的时间。 可以通过比较其 Kind 属性的值来执行此操作。

此运算符的等效方法是 DateTime.Equals(Object)

适用于

另请参阅