Bagikan melalui


DateTime.Equality(DateTime, DateTime) Operator

Definisi

Menentukan apakah dua instans DateTime yang ditentukan sama.

public:
 static bool operator ==(DateTime d1, DateTime d2);
public static bool operator ==(DateTime d1, DateTime d2);
static member ( = ) : DateTime * DateTime -> bool
Public Shared Operator == (d1 As DateTime, d2 As DateTime) As Boolean

Parameter

d1
DateTime

Objek pertama yang dibandingkan.

d2
DateTime

Objek kedua yang akan dibandingkan.

Mengembalikan

true jika d1 dan d2 mewakili tanggal dan waktu yang sama; jika tidak, false.

Contoh

Contoh berikut menunjukkan operator kesetaraan.

let april19 = DateTime(2001, 4, 19)
let otherDate = DateTime(1991, 6, 5)

// areEqual gets false.
let areEqual = april19 = otherDate

let otherDate = DateTime(2001, 4, 19)
// areEqual gets true.
let areEqual = april19 = otherDate
System.DateTime april19 = new DateTime(2001, 4, 19);
System.DateTime otherDate = new DateTime(1991, 6, 5);

// areEqual gets false.
bool areEqual = april19 == otherDate;
    
otherDate = new DateTime(2001, 4, 19);
// areEqual gets true.
areEqual = april19 == otherDate;
Dim april19 As New DateTime(2001, 4, 19)
Dim otherDate As New DateTime(1991, 6, 5)

Dim areEqual As Boolean
' areEqual gets false.
areEqual = DateTime.op_Equality(april19, otherDate)

otherDate = New DateTime(2001, 4, 19)
' areEqual gets true.
areEqual = System.DateTime.op_Equality(april19, otherDate)

Keterangan

Operator Equality menentukan apakah dua DateTime nilai sama dengan membandingkan jumlah tanda centangnya. Sebelum membandingkan DateTime objek, pastikan objek mewakili waktu dalam zona waktu yang sama. Anda dapat melakukan ini dengan membandingkan nilai propertinya Kind .

Metode yang setara untuk operator ini adalah DateTime.Equals(Object)

Berlaku untuk

Lihat juga