C# - TimeZoneInfo.Equals() Method with Example

In this tutorial, we will learn about the C# TimeZoneInfo.Equals() method with its definition, usage, syntax, and example. By Nidhi Last updated : March 31, 2023

TimeZoneInfo.Equals() Method

The TimeZoneInfo.Equals() is a static method and used to compare the object of TimeZoneInfo class with the current time-zone if both are equal then it returns true otherwise it returns false.

Syntax

bool TimeZoneInfo.Equals(TimeZoneInfo TimeZone);

Parameter(s)

  • TimeZone: Time zone to be compared with current object.

Return Value

This method returns a boolean value if the given object is equal to the current object then it returns true otherwise it returns false.

C# Example of TimeZoneInfo.Equals() Method

The source code to determine whether two TimeZoneInfo objects are equal is given below. The given program is compiled and executed successfully.

using System;
using System.Globalization;
using System.Collections.ObjectModel;

class TimeZoneInfoDemo {
  //Entry point of Program
  static public void Main() {
    TimeZoneInfo localTimeZone;
    TimeZoneInfo timeZone1;
    TimeZoneInfo timeZone2;

    localTimeZone = TimeZoneInfo.Local;

    timeZone1 = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
    timeZone2 = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");

    if (localTimeZone.Equals(timeZone1))
      Console.WriteLine("Both are equal");
    else
      Console.WriteLine("Both are not equal");

    if (localTimeZone.Equals(timeZone2))
      Console.WriteLine("Both are equal");
    else
      Console.WriteLine("Both are not equal");
  }
}

Output

Both are not equal
Both are not equal
Press any key to continue . . .

C# TimeZoneInfo Class Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.