Share via


TimeZoneInfo.IsAmbiguousTime Method (DateTime)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Determines whether a particular date and time in a particular time zone is ambiguous and can be mapped to two or more Coordinated Universal Time (UTC) times.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Function IsAmbiguousTime ( _
    dateTime As DateTime _
) As Boolean
public bool IsAmbiguousTime(
    DateTime dateTime
)

Parameters

Return Value

Type: System.Boolean
true if the dateTime parameter is ambiguous; otherwise, false.

Exceptions

Exception Condition
ArgumentException

The Kind property of the dateTime value is DateTimeKind.Local and dateTime is an invalid time.

Remarks

An ambiguous time falls within a range of times for the current time zone. This means it can be either a standard time or a time that results from the application of an adjustment rule. Typically, ambiguous times result when the clock is set to return to standard time from daylight saving time. See the Example section for an illustration.

Coordinated Universal Time (UTC) has no ambiguous times; neither do time zones that do not support daylight saving time. Therefore, these time zones have no adjustment rules and calls to the IsAmbiguousTime method always return false.

For time zones that do observe daylight saving time, the precise behavior of this method depends on the relationship between the Kind property and the TimeZoneInfo object, as the following table shows.

TimeZoneInfo object type

Kind property value

Behavior

TimeZoneInfo.Local

DateTimeKind.Local or DateTimeKind.Unspecified

Determines whether the dateTime parameter is ambiguous.

TimeZoneInfo.Local

DateTimeKind.Utc

Converts dateTime to the local time and then determines whether that time is ambiguous.

TimeZoneInfo.Utc

DateTimeKind.Utc or DateTimeKind.Unspecified

Returns false.

TimeZoneInfo.Utc

DateTimeKind.Local

If dateTime is ambiguous, assumes it is a standard time, converts it to UTC, and returns false.

Any other time zone.

DateTimeKind.Local or DateTimeKind.Utc

Converts dateTime to the time in the specified time zone and then determines whether that time is ambiguous.

Any other time zone.

DateTimeKind.Unspecified

Determines whether dateTime is ambiguous.

Version Notes

XNA Framework

 When this method is used in the XNA Framework, it throws a NotSupportedException exception.

Examples

In the Pacific Standard Time zone, which is the local time zone on the computer on which this example runs, daylight saving time ends at 2:00 A.M. on November 4, 2007. The following example passes the time at one-minute intervals from 12:59 A.M. on November 4, 2007, to 2:01 A.M. on November 4, 2007, to the IsAmbiguousTime(DateTime) method of a TimeZoneInfo object that represents the Pacific Standard Time zone. The console output indicates that all times from 1:00 A.M. on November 4, 2007, to 1:59 A.M. on November 4, 2007, are ambiguous.

' Specify DateTimeKind in Date constructor
Dim baseTime As New Date(2007, 11, 4, 0, 59, 0, DateTimeKind.Unspecified)
Dim newTime As Date

' List possible ambiguous times for 63-minute interval, from 12:59 AM to 2:01 AM 
' This assumes the local time zone is U.S. Pacific Standard Time.
For ctr As Integer = 0 To 62
   ' Because of assignment, newTime.Kind is also DateTimeKind.Unspecified
   newTime = baseTime.AddMinutes(ctr)
   outputBlock.Text &= String.Format("{0} is ambiguous: {1}", newTime, _
                       TimeZoneInfo.Local.IsAmbiguousTime(newTime)) & vbCrLf
Next
// Specify DateTimeKind in Date constructor.
DateTime baseTime = new DateTime(2007, 11, 4, 0, 59, 00, DateTimeKind.Unspecified);
DateTime newTime;

// List possible ambiguous times for 63-minute interval, from 12:59 AM to 2:01 AM. 
// This assumes the local time zone is U.S. Pacific Standard Time.
for (int ctr = 0; ctr < 63; ctr++)
{
   // Because of assignment, newTime.Kind is also DateTimeKind.Unspecified.
   newTime = baseTime.AddMinutes(ctr);
   outputBlock.Text += String.Format("{0} is ambiguous: {1}", newTime, 
                       TimeZoneInfo.Local.IsAmbiguousTime(newTime)) + "\n";
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.