TimeZoneInfo
Represents a system or custom time zone, including its base UTC offset and daylight-saving adjustment rules.
Definition
Namespace:Telerik.WinControls.UI
Assembly:Telerik.WinControls.Scheduler.dll
Syntax:
public sealed class TimeZoneInfo : IEquatable<TimeZoneInfo>, ISerializable, IDeserializationCallback
Inheritance: objectTimeZoneInfo
Implements:
Properties
Gets the zone's standard offset from UTC, before any daylight-saving adjustment is applied.
public TimeSpan BaseUtcOffset { get; }
Gets the name used while daylight-saving time is in effect, or an empty string when none is configured.
public string DaylightName { get; }
Gets the name shown for this zone, which can differ from its identifier and is empty if none is configured.
public string DisplayName { get; }
Gets the cached system local time zone; ClearCachedData() resets this value.
public static TimeZoneInfo Local { get; }
Gets the name used while standard time is in effect, or an empty string when none is configured.
public string StandardName { get; }
Gets whether daylight-saving adjustment rules are enabled, not whether they apply at a particular date.
public bool SupportsDaylightSavingTime { get; }
Gets the zero-offset UTC time zone.
public static TimeZoneInfo Utc { get; }
Methods
Clears the cached local, UTC, and system time-zone data so subsequent lookups reload it.
public static void ClearCachedData()
Converts a value from an explicitly supplied source zone to a destination zone using both zones' adjustment rules.
public static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
The value to convert.
sourceTimeZoneTimeZoneInfoThe zone in which dateTime is expressed.
The zone to convert to.
Returns:The date and time adjusted to the destination zone.
Exceptions: ArgumentNullExceptionEither time-zone argument is null.
ArgumentExceptiondateTime has a kind that conflicts with the source zone, or represents an invalid local time.
Converts a value to the destination zone, treating UTC values as UTC and other values as local time.
public static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo destinationTimeZone)
The value to convert.
destinationTimeZoneTimeZoneInfoThe time zone to convert to.
Returns:The date and time adjusted to the destination zone.
Exceptions: ArgumentNullExceptiondestinationTimeZone is null.
dateTime is an invalid local time.
Converts the represented instant to the destination zone while retaining it as a DateTimeOffset.
public static DateTimeOffset ConvertTime(DateTimeOffset dateTimeOffset, TimeZoneInfo destinationTimeZone)
The instant to convert.
destinationTimeZoneTimeZoneInfoThe time zone to convert to.
Returns:The instant with the destination zone's offset, clamped to the DateTimeOffset range if needed.
Exceptions: ArgumentNullExceptiondestinationTimeZone is null.
Converts a value between system time zones identified by their IDs.
public static DateTime ConvertTimeBySystemTimeZoneId(DateTime dateTime, string sourceTimeZoneId, string destinationTimeZoneId)
The value to convert.
sourceTimeZoneIdstringThe ID of the source system time zone.
destinationTimeZoneIdstringThe ID of the destination system time zone.
Returns:The converted value.
Exceptions: ArgumentNullExceptionEither time-zone ID is null.
TimeZoneNotFoundExceptionEither ID does not identify a system time zone.
InvalidTimeZoneExceptionThe data for a requested time zone is invalid.
SecurityExceptionAccess to system time-zone data is denied.
ArgumentExceptiondateTime has a kind that conflicts with the source zone, or represents an invalid local time.
Converts a local or UTC value to a system time zone identified by its ID.
public static DateTime ConvertTimeBySystemTimeZoneId(DateTime dateTime, string destinationTimeZoneId)
The value to convert; UTC values use UTC as the source, and other values use the local zone.
destinationTimeZoneIdstringThe ID of the destination system time zone.
Returns:The converted value.
Exceptions: ArgumentNullExceptiondestinationTimeZoneId is null.
The destination ID does not identify a system time zone.
InvalidTimeZoneExceptionThe system time-zone data is invalid.
SecurityExceptionAccess to system time-zone data is denied.
ArgumentExceptiondateTime is an invalid local time.
Converts an instant to a system time zone identified by its ID.
public static DateTimeOffset ConvertTimeBySystemTimeZoneId(DateTimeOffset dateTimeOffset, string destinationTimeZoneId)
The instant to convert.
destinationTimeZoneIdstringThe ID of the destination system time zone.
Returns:The instant with the destination zone's offset.
Exceptions: ArgumentNullExceptiondestinationTimeZoneId is null.
The destination ID does not identify a system time zone.
InvalidTimeZoneExceptionThe system time-zone data is invalid.
SecurityExceptionAccess to system time-zone data is denied.
Converts a UTC value to the destination time zone.
public static DateTime ConvertTimeFromUtc(DateTime dateTime, TimeZoneInfo destinationTimeZone)
The value expressed in UTC.
destinationTimeZoneTimeZoneInfoThe destination time zone.
Returns:The converted value.
Exceptions: ArgumentNullExceptiondestinationTimeZone is null.
dateTime has local kind rather than UTC.
Converts a value from the supplied source time zone to UTC.
public static DateTime ConvertTimeToUtc(DateTime dateTime, TimeZoneInfo sourceTimeZone)
The value to convert.
sourceTimeZoneTimeZoneInfoThe zone in which dateTime is expressed.
The value expressed in UTC.
Exceptions: ArgumentNullExceptionsourceTimeZone is null.
dateTime has a kind that conflicts with the source zone, or represents an invalid local time.
Converts a local value to UTC; values already marked as UTC are returned unchanged.
public static DateTime ConvertTimeToUtc(DateTime dateTime)
The value to convert; an unspecified or local value is treated as local time.
Returns:The value expressed in UTC.
Exceptions: ArgumentExceptiondateTime is an invalid local time.
Creates a custom time zone from adjustment rules, optionally disabling their daylight-saving behavior.
public static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string daylightDisplayName, TimeZoneInfo.AdjustmentRule[] adjustmentRules, bool disableDaylightSavingTime)
The identifier for the custom zone.
baseUtcOffsetTimeSpanThe zone's standard offset from UTC.
displayNamestringThe name shown when the zone is displayed.
standardDisplayNamestringThe name used while standard time is in effect.
daylightDisplayNamestringThe name used while daylight-saving time is enabled.
adjustmentRulesAdjustmentRule[]The date ranges and transition rules to associate with the zone; null or empty means no adjustments.
disableDaylightSavingTimeboolIf true, the zone ignores daylight-saving adjustments.
Returns:A custom time zone configured with the supplied offset and rules.
Exceptions: ArgumentNullExceptionid is null.
id is empty or the offset contains sub-minute precision.
baseUtcOffset is outside the supported UTC-offset range.
An adjustment-rule entry is null, rules overlap, or a rule produces an unsupported offset.
Creates a custom time zone whose adjustment rules define its daylight-saving transitions.
public static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string daylightDisplayName, TimeZoneInfo.AdjustmentRule[] adjustmentRules)
The identifier for the custom zone.
baseUtcOffsetTimeSpanThe zone's standard offset from UTC.
displayNamestringThe name shown when the zone is displayed.
standardDisplayNamestringThe name used while standard time is in effect.
daylightDisplayNamestringThe name used while daylight-saving time is in effect.
adjustmentRulesAdjustmentRule[]The date ranges and transition rules that adjust the base offset; null or empty means no adjustments.
Returns:A custom time zone configured with the supplied adjustment rules.
Exceptions: ArgumentNullExceptionid is null.
id is empty or the offset contains sub-minute precision.
baseUtcOffset is outside the supported UTC-offset range.
An adjustment-rule entry is null, rules overlap, or a rule produces an unsupported offset.
Creates a custom time zone with a fixed UTC offset and no daylight-saving adjustment rules.
public static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName)
The identifier for the custom zone.
baseUtcOffsetTimeSpanThe zone's standard offset from UTC.
displayNamestringThe name shown when the zone is displayed.
standardDisplayNamestringThe name used while standard time is in effect.
Returns:A custom time zone without daylight-saving transitions.
Exceptions: ArgumentNullExceptionid is null.
id is empty or the offset contains sub-minute precision.
baseUtcOffset is outside the supported UTC-offset range.
Determines whether another zone has the same identifier and adjustment rules.
public bool Equals(TimeZoneInfo other)
The zone to compare with this instance.
Returns:Implements:
Retrieves a system time zone by its identifier.
public static TimeZoneInfo FindSystemTimeZoneById(string id)
The system time-zone identifier; "UTC" resolves to Utc.
Returns:The matching system time zone.
Exceptions: ArgumentNullExceptionid is null.
No system time zone has the specified identifier.
InvalidTimeZoneExceptionThe registry data for the requested zone is invalid.
SecurityExceptionAccess to system time-zone data is denied.
Creates a time zone from the serialized representation produced by ToSerializedString().
public static TimeZoneInfo FromSerializedString(string source)
The serialized time-zone data.
Returns:The time zone described by source.
source is null.
source is empty.
source is malformed or does not describe a valid time zone.
Gets a copy of the daylight-saving adjustment rules associated with this zone.
public TimeZoneInfo.AdjustmentRule[] GetAdjustmentRules()
The rules that apply over this zone's date ranges, or an empty array when it has none.
Gets the two possible UTC offsets for a date/time that occurs twice during a daylight-saving transition.
public TimeSpan[] GetAmbiguousTimeOffsets(DateTime dateTime)
The potentially ambiguous wall-clock value.
Returns:TimeSpan[]
The standard and daylight offsets that can represent the same local time.
Exceptions: ArgumentExceptiondateTime is not ambiguous in this zone.
Gets the two possible UTC offsets for the local time represented by an offset value in this zone.
public TimeSpan[] GetAmbiguousTimeOffsets(DateTimeOffset dateTimeOffset)
The value to test after converting its instant to this zone.
Returns:TimeSpan[]
The standard and daylight offsets that can represent the same local time.
Exceptions: ArgumentExceptiondateTimeOffset does not map to an ambiguous local time in this zone.
Returns a hash code derived from the time-zone identifier.
Gets the system time zones as a read-only collection.
[SecurityCritical]
public static ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones()
ReadOnlyCollection<TimeZoneInfo>
A cached, read-only collection of the available system time zones.
Exceptions: SecurityExceptionAccess to system time-zone data is denied.
Gets this zone's UTC offset for a date/time, applying the relevant daylight-saving rule.
Gets this zone's UTC offset at the instant represented by a DateTimeOffset.
public TimeSpan GetUtcOffset(DateTimeOffset dateTimeOffset)
The instant whose offset is requested.
Returns:The offset from UTC at that instant.
Determines whether another zone has the same base offset and daylight-saving adjustment rules. Identifiers and display names are not compared.
public bool HasSameRules(TimeZoneInfo other)
The zone to compare with this instance.
Returns: Exceptions: ArgumentNullExceptionother is null.
Determines whether the instant represented by a DateTimeOffset maps to an ambiguous local time in this zone.
public bool IsAmbiguousTime(DateTimeOffset dateTimeOffset)
The value to examine.
Returns:true if the converted local time has two possible UTC offsets; otherwise, false.
Determines whether daylight-saving time applies in this zone at the instant represented by a DateTimeOffset.
public bool IsDaylightSavingTime(DateTimeOffset dateTimeOffset)
The instant to examine.
Returns:Determines whether a wall-clock value falls in the gap created by a forward daylight-saving transition.
Serializes this zone's identifier, display names, base offset, and adjustment rules.
public string ToSerializedString()
A string that can be parsed by FromSerializedString(string).
Returns the zone's DisplayName.