C# program to determine whether two TimeZoneInfo objects are equal (TimeZoneInfo.Equals() Method)

C# TimeZoneInfo.Equals() Method: Here, we are going to learn how to determine whether two TimeZoneInfo objects are equal in C#.Net?
Submitted by Nidhi, on May 19, 2021

The Equals() method of TimeZoneInfo class 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.

Program:

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 »


ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.