Ask Learn
Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.
IsAmbiguousTime(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. |
IsAmbiguousTime(DateTimeOffset) |
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. |
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.
public:
bool IsAmbiguousTime(DateTime dateTime);
public bool IsAmbiguousTime(DateTime dateTime);
member this.IsAmbiguousTime : DateTime -> bool
Public Function IsAmbiguousTime (dateTime As DateTime) As Boolean
A date and time value.
true
if the dateTime
parameter is ambiguous; otherwise, false
.
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));
}
// Specify DateTimeKind in Date constructor
let baseTime = DateTime(2007, 11, 4, 0, 59, 00, DateTimeKind.Unspecified)
// Get Pacific Standard Time zone
let pstZone = TimeZoneInfo.FindSystemTimeZoneById "Pacific Standard Time"
// List possible ambiguous times for 63-minute interval, from 12:59 AM to 2:01 AM
for i = 0 to 62 do
// Because of assignment, newTime.Kind is also DateTimeKind.Unspecified
let newTime = baseTime.AddMinutes i
printfn $"{newTime} is ambiguous: {pstZone.IsAmbiguousTime newTime}"
' Specify DateTimeKind in Date constructor
Dim baseTime As New Date(2007, 11, 4, 0, 59, 00, DateTimeKind.Unspecified)
Dim newTime As Date
' Get Pacific Standard Time zone
Dim pstZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time")
' List possible ambiguous times for 63-minute interval, from 12:59 AM to 2:01 AM
For ctr As Integer = 0 To 62
' Because of assignment, newTime.Kind is also DateTimeKind.Unspecified
newTime = baseTime.AddMinutes(ctr)
Console.WriteLine("{0} is ambiguous: {1}", newTime, pstZone.IsAmbiguousTime(newTime))
Next
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. |
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
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.
public:
bool IsAmbiguousTime(DateTimeOffset dateTimeOffset);
public bool IsAmbiguousTime(DateTimeOffset dateTimeOffset);
member this.IsAmbiguousTime : DateTimeOffset -> bool
Public Function IsAmbiguousTime (dateTimeOffset As DateTimeOffset) As Boolean
A date and time.
true
if the dateTimeOffset
parameter is ambiguous in the current time zone; otherwise, false
.
An ambiguous time falls within a range of times for the current time zone. This means that 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. Coordinated Universal Time (UTC) has no ambiguous times; neither do time zones that do not support daylight saving time.
The precise behavior of the method depends on the relationship between the Offset property of the dateTimeOffset
parameter and the current time zone. If the value of the Offset property is a possible offset from the UTC of the current time zone, the method determines whether that date and time is ambiguous. Otherwise, it converts dateTimeOffset
to the time in the current time zone, and then determines whether that date and time is ambiguous.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Please sign in to use this experience.
Sign in