C# program to check whether a date and time in a particular time zone is ambiguous (TimeZoneInfo.IsAmbiguousTime() Method)

C# TimeZoneInfo.IsAmbiguousTime() Method: Here, we are going to learn how to check whether a date and time in a particular time zone is ambiguous in C#.Net?
Submitted by Nidhi, on May 20, 2021

The IsAmbiguousTime() method of the TimeZoneInfo class is used to check whether a given date and time in a particular time zone is ambiguous or not and can be mapped to two or more UTC times.

Syntax:

    bool TimeZoneInfo.IsAmbiguousTime (DateTime date_time);

Parameter(s):

  • date_time: The date time value to be checked whether it is ambiguous or not.

Return value:

This method returns a boolean value if the given time is ambiguous in a particular time zone then it returns true otherwise it returns false.

Exception(s):

  • System.ArgumentException

Program:

The source code to check whether a date and time in a particular time zone is ambiguous 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()
    {
        DateTime ambiguousTime;

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

        ambiguousTime = new DateTime(2007, 11, 4, 1, 0, 0);

        if (timeZone1.IsAmbiguousTime(ambiguousTime))
            Console.WriteLine("Time is ambiguous");
        else
            Console.WriteLine("Time is not ambiguous");

        if (timeZone2.IsAmbiguousTime(ambiguousTime))
            Console.WriteLine("Time is ambiguous");
        else
            Console.WriteLine("Time is not ambiguous");
    }
}

Output:

Time is ambiguous
Time is not ambiguous
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.