C# - TimeZoneInfo.IsAmbiguousTime() Method with Example

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

TimeZoneInfo.IsAmbiguousTime() Method

The TimeZoneInfo.IsAmbiguousTime() 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

C# Example of TimeZoneInfo.GetUtcOffset() Method

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 »





Comments and Discussions!

Load comments ↻





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