C# DateTime Equals(DateTime)

Description

DateTime Equals(DateTime) returns a value indicating whether the value of this instance is equal to the value of the specified DateTime instance.

Syntax

DateTime.Equals(DateTime) has the following syntax.


public bool Equals(
  DateTime value
)

Parameters

DateTime.Equals(DateTime) has the following parameters.

  • value - The object to compare to this instance.

Returns

DateTime.Equals(DateTime) method returns true if the value parameter equals the value of this instance; otherwise, false.

Example

The following example demonstrates the Equals method.


//w w  w . ja v a  2 s  .  c  om
using System;

public class Application
{
    public static void Main()
    {
        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);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version