다음을 통해 공유


DateTime.Equals 메서드

정의

DateTime 개체 또는 DateTime 인스턴스와 다른 DateTime개체 또는 값이 같은지 여부를 나타내는 값을 반환합니다.

오버로드

Name Description
Equals(DateTime)

이 인스턴스의 값이 지정된 DateTime 인스턴스의 값과 같은지 여부를 나타내는 값을 반환합니다.

Equals(Object)

이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

Equals(DateTime, DateTime)

DateTime 인스턴스의 날짜 및 시간 값이 같은지 여부를 나타내는 값을 반환합니다.

Equals(DateTime)

Source:
DateTime.cs
Source:
DateTime.cs
Source:
DateTime.cs
Source:
DateTime.cs
Source:
DateTime.cs

이 인스턴스의 값이 지정된 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

매개 변수

value
DateTime

이 인스턴스와 비교할 개체입니다.

반환

true 매개 변수가 value 이 인스턴스의 값과 같으면 .이고, false그렇지 않으면 .입니다.

구현

예제

다음 예제에서는 메서드를 보여 줍니다 Equals .

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.
open System

// Create some DateTime objects.
let one = DateTime.UtcNow

let two = DateTime.Now

let three = one

// Compare the DateTime objects and display the results.
let result = one.Equals two

printfn $"The result of comparing DateTime object one and two is: {result}."

let result2 = one.Equals three

printfn $"The result of comparing DateTime object one and three is: {result2}."

// 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.

설명

현재 인스턴스이며 value 속성 값이 같으면 Ticks 같습니다. 해당 Kind 속성 값은 같음 테스트에 고려되지 않습니다.

이 메서드는 인터페이스를 System.IEquatable<T> 구현하고 매개 변수를 Equals 개체로 변환할 필요가 없으므로 메서드 value 보다 약간 더 잘 수행됩니다.

추가 정보

적용 대상

Equals(Object)

Source:
DateTime.cs
Source:
DateTime.cs
Source:
DateTime.cs
Source:
DateTime.cs
Source:
DateTime.cs

이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

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

매개 변수

value
Object

이 인스턴스와 비교할 개체입니다.

반환

true인스턴스이고 이 인스턴스의 DateTime 값과 같으면 value .이고, false그렇지 않으면 .

예제

다음 예제에서는 메서드를 보여 줍니다 Equals .

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.
open System

// Create some DateTime objects.
let one = DateTime.UtcNow

let two = DateTime.Now

let three = one

// Compare the DateTime objects and display the results.
let result = one.Equals two

printfn $"The result of comparing DateTime object one and two is: {result}."

let result2 = one.Equals three

printfn $"The result of comparing DateTime object one and three is: {result2}."

// 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.

설명

현재 인스턴스이며 value 속성 값이 같으면 Ticks 같습니다. 해당 Kind 속성 값은 같음 테스트에 고려되지 않습니다.

추가 정보

적용 대상

Equals(DateTime, DateTime)

Source:
DateTime.cs
Source:
DateTime.cs
Source:
DateTime.cs
Source:
DateTime.cs
Source:
DateTime.cs

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

매개 변수

t1
DateTime

비교할 첫 번째 개체입니다.

t2
DateTime

비교할 두 번째 개체입니다.

반환

true두 값이 같으면 이고, 그렇지 않으면 . false

예제

다음 예제에서는 메서드를 보여 줍니다 Equals .

let today1 = 
    System.DateTime System.DateTime.Today.Ticks

let today2 =
    System.DateTime System.DateTime.Today.Ticks

let tomorrow =
    System.DateTime.Today.AddDays(1).Ticks
    |> System.DateTime 

// todayEqualsToday gets true.
let todayEqualsToday = System.DateTime.Equals(today1, today2)

// todayEqualsTomorrow gets false.
let 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)

설명

t1 속성 t2 값이 같으면 Ticks 같음입니다. 해당 Kind 속성 값은 같음 테스트에 고려되지 않습니다.

추가 정보

적용 대상