DateTime.Equality(DateTime, DateTime) Operador

Definición

Determina si dos instancias especificadas de DateTime son iguales.

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

Parámetros

d1
DateTime

Primer objeto que se va a comparar.

d2
DateTime

Segundo objeto que se va a comparar.

Devoluciones

Boolean

true si d1 y d2 representan la misma fecha y hora; en caso contrario, false.

Ejemplos

En el ejemplo siguiente se muestra el operador de igualdad.

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;
let april19 = DateTime(2001, 4, 19)
let otherDate = DateTime(1991, 6, 5)

// areEqual gets false.
let areEqual = april19 = otherDate

let otherDate = DateTime(2001, 4, 19)
// areEqual gets true.
let 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)

Comentarios

El Equality operador determina si dos DateTime valores son iguales comparando su número de tics. Antes de DateTime comparar objetos, asegúrese de que los objetos representan horas en la misma zona horaria. Puede hacerlo comparando los valores de su propiedad Kind.

El método equivalente para este operador es DateTime.Equals(Object)

Se aplica a

Consulte también