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.

C#
public override bool Equals(object? obj);
C#
public override bool Equals(object obj);

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.

C#
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

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

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Equals(TimeZoneInfo)

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

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

C#
public bool Equals(TimeZoneInfo other);
C#
public bool Equals(TimeZoneInfo? other);

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.

C#
   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));

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:

C#
other.Id == this.Id && HasSameRules(other);

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

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0