DateTime.Equals メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
オーバーロード
| 名前 | 説明 |
|---|---|
| Equals(DateTime) |
このインスタンスの値が、指定した DateTime インスタンスの値と等しいかどうかを示す値を返します。 |
| Equals(Object) |
このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。 |
| Equals(DateTime, DateTime) |
2 つの DateTime インスタンスの日付と時刻の値が同じかどうかを示す値を返します。 |
Equals(DateTime)
- ソース:
- DateTime.cs
- ソース:
- DateTime.cs
- ソース:
- DateTime.cs
- ソース:
- DateTime.cs
- ソース:
- 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 パラメーターがこのインスタンスの値と等しい場合は @a0/>。それ以外の場合は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> インターフェイスを実装し、value パラメーターをオブジェクトに変換する必要がないため、Equals メソッドよりも若干優れたパフォーマンスを発揮します。
こちらもご覧ください
適用対象
Equals(Object)
- ソース:
- DateTime.cs
- ソース:
- DateTime.cs
- ソース:
- DateTime.cs
- ソース:
- DateTime.cs
- ソース:
- 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
valueがDateTimeのインスタンスであり、このインスタンスの値と等しい場合は ɦ。それ以外の場合は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)
- ソース:
- DateTime.cs
- ソース:
- DateTime.cs
- ソース:
- DateTime.cs
- ソース:
- DateTime.cs
- ソース:
- DateTime.cs
2 つの 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
比較する 2 番目のオブジェクト。
戻り値
true 2 つの値が等しい場合。それ以外の場合は 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
Ticksプロパティ値が等しい場合、t2は等しくなります。 これらの Kind プロパティ値は、等しいかどうかをテストでは考慮されません。