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

定义

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

d2
DateTime DateTime DateTime DateTime

示例

``````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)
``````

注解

@No__t-0 运算符通过比较两个 @no__t 值的计时周期数来确定这两个值是否相等。The 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.