DateTime.Equality(DateTime, DateTime) DateTime.Equality(DateTime, DateTime) DateTime.Equality(DateTime, DateTime) DateTime.Equality(DateTime, DateTime) Operator

定义

确定 DateTime 的两个指定的实例是否相等。Determines whether two specified instances of DateTime are equal.

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 DateTime DateTime DateTime

要比较的第一个对象。The first object to compare.

d2
DateTime DateTime DateTime DateTime

要比较的第二个对象。The second object to compare.

返回

如果 trued1 表示同一日期和时间,则为 d2;否则为 falsetrue if d1 and d2 represent the same date and time; otherwise, false.

示例

下面的示例演示了相等运算符。The following example demonstrates the equality operator.

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)

注解

运算符通过比较两个DateTime值的计时周期数来确定这两个值是否相等。 EqualityThe Equality operator determines whether two DateTime values are equal by comparing their number of ticks. 在比较DateTime对象之前,请确保对象表示相同时区中的时间。Before comparing DateTime objects, make sure that the objects represent times in the same time zone. 可以通过比较其 Kind 属性的值来执行此操作。You can do this by comparing the values of their Kind property.

此运算符的等效方法是DateTime.Equals(Object)The equivalent method for this operator is DateTime.Equals(Object)

适用于

另请参阅