편집

다음을 통해 공유


TimeZoneInfo.Equals Method

Definition

Determines whether two TimeZoneInfo objects are equal.

Overloads

Equals(Object)

Determines whether the current TimeZoneInfo object and another object are equal.

Equals(TimeZoneInfo)

Determines whether the current TimeZoneInfo object and another TimeZoneInfo object are equal.

Equals(Object)

Source:
TimeZoneInfo.cs
Source:
TimeZoneInfo.cs
Source:
TimeZoneInfo.cs

Determines whether the current TimeZoneInfo object and another object are equal.

public:
 override bool Equals(System::Object ^ obj);
public override bool Equals (object? obj);
public override bool Equals (object obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean

Parameters

obj
Object

A second object to compare with the current object.

Returns

true if obj is a TimeZoneInfo object that is equal to the current instance; otherwise, false.

Examples

The following example uses the Equals(Object) method to determine whether the local time zone is Pacific Time or Eastern Time.

using System;

public class Example
{
   public static void Main()
   {
      TimeZoneInfo thisTimeZone;
      object obj1, obj2;
      
      thisTimeZone = TimeZoneInfo.Local;
      obj1 = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
      obj2 = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
      Console.WriteLine(thisTimeZone.Equals(obj1));
      Console.WriteLine(thisTimeZone.Equals(obj2));
   }
}
// The example displays the following output:
//      True
//      False
open System

let thisTimeZone = TimeZoneInfo.Local
let obj1 = TimeZoneInfo.FindSystemTimeZoneById "Pacific Standard Time"
let obj2 = TimeZoneInfo.FindSystemTimeZoneById "Eastern Standard Time"
printfn $"{thisTimeZone.Equals obj1}"
printfn $"{thisTimeZone.Equals obj2}"
// The example displays the following output:
//      True
//      False
Module Example
   Public Sub Main()
      Dim thisTimeZone As TimeZoneInfo
      Dim obj1, obj2 As Object
      
      thisTimeZone = TimeZoneInfo.Local
      obj1 = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time")
      obj2 = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")
      Console.WriteLine(thisTimeZone.Equals(obj1))
      Console.WriteLine(thisTimeZone.Equals(obj2))
   End Sub
End Module
' The example displays the following output:
'      True
'      False

Remarks

This method converts or casts obj to a TimeZoneInfo object and compares it with the current instance. The test for equality is based on a comparison of values. The current TimeZoneInfo instance and obj are considered to be equal under the following conditions:

  • The run-time type of obj is TimeZoneInfo.

  • The two objects have the same Id property value.

  • The two objects have the same adjustment rules.

If obj is null, this method returns false.

Applies to

Equals(TimeZoneInfo)

Source:
TimeZoneInfo.cs
Source:
TimeZoneInfo.cs
Source:
TimeZoneInfo.cs

Determines whether the current TimeZoneInfo object and another TimeZoneInfo object are equal.

public:
 virtual bool Equals(TimeZoneInfo ^ other);
public bool Equals (TimeZoneInfo other);
public bool Equals (TimeZoneInfo? other);
override this.Equals : TimeZoneInfo -> bool
Public Function Equals (other As TimeZoneInfo) As Boolean

Parameters

other
TimeZoneInfo

A second object to compare with the current object.

Returns

true if the two TimeZoneInfo objects are equal; otherwise, false.

Implements

Examples

The following example uses the Equals(TimeZoneInfo) method to determine whether the local time zone is Pacific Time or Eastern Time.

   TimeZoneInfo thisTimeZone, zone1, zone2;

   thisTimeZone = TimeZoneInfo.Local;
   zone1 = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
   zone2 = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
   Console.WriteLine(thisTimeZone.Equals(zone1));
   Console.WriteLine(thisTimeZone.Equals(zone2));
let thisTimeZone = TimeZoneInfo.Local
let zone1 = TimeZoneInfo.FindSystemTimeZoneById "Pacific Standard Time"
let zone2 = TimeZoneInfo.FindSystemTimeZoneById "Eastern Standard Time"
printfn $"{thisTimeZone.Equals zone1}"
printfn $"{thisTimeZone.Equals zone2}"
Dim thisTimeZone, zone1, zone2 As TimeZoneInfo

thisTimeZone = TimeZoneInfo.Local
zone1 = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time")
zone2 = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")
Console.WriteLine(thisTimeZone.Equals(zone1))
Console.WriteLine(thisTimeZone.Equals(zone2))

Remarks

Equality is based on a comparison of values. Two TimeZoneInfo objects are considered to be equal under the following conditions:

  • The value of their Id property is the same.

  • They have the same adjustment rules.

TimeZoneInfo.Equals(TimeZoneInfo) returns the Boolean value that results from evaluating the following expression:

other.Id == this.Id && HasSameRules(other);
other.Id = me.Id AndAlso HasSameRules(other)

If the other parameter is an uninitialized TimeZoneInfo object, this method returns false.

Applies to