C# Program to Determine Whether Two Timezoneinfo Objects Are Equal (Timezoneinfo.equals() Method)

You are currently viewing C# Program to Determine Whether Two Timezoneinfo Objects Are Equal (Timezoneinfo.equals() Method)

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

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");
    }
}
Both are not equal
Both are not equal
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply