DateTime.Equals Método
Definición
Sobrecargas
Equals(DateTime, DateTime) |
Devuelve un valor que indica si dos instancias de DateTime tienen el mismo valor de fecha y hora.Returns a value indicating whether two DateTime instances have the same date and time value. |
Equals(DateTime) |
Devuelve un valor que indica si el valor de esta instancia equivale al valor de la instancia de DateTime especificada.Returns a value indicating whether the value of this instance is equal to the value of the specified DateTime instance. |
Equals(Object) |
Devuelve un valor que indica si esta instancia equivale a un objeto especificado.Returns a value indicating whether this instance is equal to a specified object. |
Equals(DateTime, DateTime)
public:
static bool Equals(DateTime t1, DateTime t2);
public static bool Equals (DateTime t1, DateTime t2);
static member Equals : DateTime * DateTime -> bool
Public Shared Function Equals (t1 As DateTime, t2 As DateTime) As Boolean
Parámetros
- t1
- DateTime
Primer objeto que se va a comparar.The first object to compare.
- t2
- DateTime
Segundo objeto que se va a comparar.The second object to compare.
Devoluciones
true
si los dos valores son iguales; en caso contrario, false
.true
if the two values are equal; otherwise, false
.
Ejemplos
En el siguiente ejemplo se muestra el Equals método.The following example demonstrates the Equals method.
System::DateTime today1 = System::DateTime(
System::DateTime::Today.Ticks );
System::DateTime today2 = System::DateTime(
System::DateTime::Today.Ticks );
System::DateTime tomorrow = 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 );
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);
Dim today1 As New System.DateTime(System.DateTime.Today.Ticks)
Dim today2 As New System.DateTime(System.DateTime.Today.Ticks)
Dim tomorrow As New System.DateTime( _
System.DateTime.Today.AddDays(1).Ticks)
' todayEqualsToday gets true.
Dim todayEqualsToday As Boolean = System.DateTime.Equals(today1, today2)
' todayEqualsTomorrow gets false.
Dim todayEqualsTomorrow As Boolean = System.DateTime.Equals(today1, tomorrow)
Comentarios
t1
y t2
son iguales si sus Ticks valores de propiedad son iguales.t1
and t2
are equal if their Ticks property values are equal. Los Kind valores de sus propiedades no se tienen en cuenta en la prueba para comprobar si son iguales.Their Kind property values are not considered in the test for equality.
Consulte también
Se aplica a
Equals(DateTime)
public:
virtual bool Equals(DateTime value);
public bool Equals (DateTime value);
override this.Equals : DateTime -> bool
Public Function Equals (value As DateTime) As Boolean
Parámetros
- value
- DateTime
Objeto que se va a comparar con esta instancia.The object to compare to this instance.
Devoluciones
true
si el parámetro value
es igual al valor de esta instancia; en caso contrario, false
.true
if the value
parameter equals the value of this instance; otherwise, false
.
Implementaciones
Ejemplos
En el siguiente ejemplo se muestra el Equals método.The following example demonstrates the Equals method.
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.
Module Application
Sub Main()
' Create some DateTime objects.
Dim one As DateTime = DateTime.UtcNow
Dim two As DateTime = DateTime.Now
Dim three As DateTime = one
' Compare the DateTime objects and display the results.
Dim result As Boolean = 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)
End Sub
End Module
' 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.
Comentarios
La instancia actual y value
son iguales si sus Ticks valores de propiedad son iguales.The current instance and value
are equal if their Ticks property values are equal. Los Kind valores de sus propiedades no se tienen en cuenta en la prueba para comprobar si son iguales.Their Kind property values are not considered in the test for equality.
Este método implementa la System.IEquatable<T> interfaz y se ejecuta ligeramente mejor que el Equals método porque value
no es necesario convertir el parámetro en un objeto.This method implements the System.IEquatable<T> interface, and performs slightly better than the Equals method because the value
parameter does not have to be converted to an object.
Consulte también
Se aplica a
Equals(Object)
Devuelve un valor que indica si esta instancia equivale a un objeto especificado.Returns a value indicating whether this instance is equal to a specified object.
public:
override bool Equals(System::Object ^ value);
public override bool Equals (object value);
public override bool Equals (object? value);
override this.Equals : obj -> bool
Public Overrides Function Equals (value As Object) As Boolean
Parámetros
- value
- Object
Objeto que se va a comparar con esta instancia.The object to compare to this instance.
Devoluciones
true
si value
es una instancia de DateTime y es igual al valor de esta instancia; en caso contrario, false
.true
if value
is an instance of DateTime and equals the value of this instance; otherwise, false
.
Ejemplos
En el siguiente ejemplo se muestra el Equals método.The following example demonstrates the Equals method.
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.
Module Application
Sub Main()
' Create some DateTime objects.
Dim one As DateTime = DateTime.UtcNow
Dim two As DateTime = DateTime.Now
Dim three As DateTime = one
' Compare the DateTime objects and display the results.
Dim result As Boolean = 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)
End Sub
End Module
' 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.
Comentarios
La instancia actual y value
son iguales si sus Ticks valores de propiedad son iguales.The current instance and value
are equal if their Ticks property values are equal. Los Kind valores de sus propiedades no se tienen en cuenta en la prueba para comprobar si son iguales.Their Kind property values are not considered in the test for equality.