C# DateTime Equals(DateTime, DateTime)
Description
DateTime Equals(DateTime, DateTime)
returns a value
indicating whether two DateTime instances have the same date and time value.
Syntax
DateTime.Equals(DateTime, DateTime)
has the following syntax.
public static bool Equals(
DateTime t1,
DateTime t2
)
Parameters
DateTime.Equals(DateTime, DateTime)
has the following parameters.
t1
- The first object to compare.t2
- The second object to compare.
Returns
DateTime.Equals(DateTime, DateTime)
method returns true if the two values are equal; otherwise, false.
Example
The following example demonstrates the Equals method.
using System;//from w w w .j a v a 2 s . c om
public class MainClass{
public static void Main(String[] argv){
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);
System.Console.WriteLine(todayEqualsToday);
// todayEqualsTomorrow gets false.
bool todayEqualsTomorrow = System.DateTime.Equals(today1, tomorrow);
System.Console.WriteLine(todayEqualsTomorrow);
}
}
The code above generates the following result.