Export (0) Print
Expand All

TimeZoneInfo.IsAmbiguousTime Method (DateTime)

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)

public bool IsAmbiguousTime(
	DateTime dateTime
)

Parameters

dateTime
Type: System.DateTime

A date and time value.

Return Value

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

ExceptionCondition
ArgumentException

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

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.

Notes to Callers

On Windows XP systems, this method applies only the current adjustment rule if the current instance is TimeZoneInfo.Local. As a result, the method may not accurately report whether dateTime is an ambiguous time for periods before the current adjustment rule came into effect. For more information, see the Notes for Callers section in the Local property.

In the Pacific Time zone, 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 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
DateTime baseTime = new DateTime(2007, 11, 4, 0, 59, 00, DateTimeKind.Unspecified);
DateTime newTime;

// Get Pacific Standard Time zone
TimeZoneInfo pstZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");

// List possible ambiguous times for 63-minute interval, from 12:59 AM to 2:01 AM  
for (int ctr = 0; ctr < 63; ctr++)
{
   // Because of assignment, newTime.Kind is also DateTimeKind.Unspecified
   newTime = baseTime.AddMinutes(ctr);   
   Console.WriteLine("{0} is ambiguous: {1}", newTime, pstZone.IsAmbiguousTime(newTime));
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft