New to Telerik UI for WinForms? Start a free 30-day trial

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:

C#
public sealed class TimeZoneInfo : IEquatable<TimeZoneInfo>, ISerializable, IDeserializationCallback

Inheritance: objectTimeZoneInfo

Implements: IDeserializationCallbackIEquatable<TimeZoneInfo>ISerializable

Properties

Gets the zone's standard offset from UTC, before any daylight-saving adjustment is applied.

C#
public TimeSpan BaseUtcOffset { get; }

Gets the name used while daylight-saving time is in effect, or an empty string when none is configured.

C#
public string DaylightName { get; }

Gets the name shown for this zone, which can differ from its identifier and is empty if none is configured.

C#
public string DisplayName { get; }

Gets the identifier used to find or serialize this time zone.

C#
public string Id { get; }

Gets the cached system local time zone; ClearCachedData() resets this value.

C#
public static TimeZoneInfo Local { get; }

Gets the name used while standard time is in effect, or an empty string when none is configured.

C#
public string StandardName { get; }

Gets whether daylight-saving adjustment rules are enabled, not whether they apply at a particular date.

C#
public bool SupportsDaylightSavingTime { get; }

Gets the zero-offset UTC time zone.

C#
public static TimeZoneInfo Utc { get; }

Methods

Clears the cached local, UTC, and system time-zone data so subsequent lookups reload it.

C#
public static void ClearCachedData()

Converts a value from an explicitly supplied source zone to a destination zone using both zones' adjustment rules.

C#
public static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
Parameters:dateTimeDateTime

The value to convert.

sourceTimeZoneTimeZoneInfo

The zone in which dateTime is expressed.

destinationTimeZoneTimeZoneInfo

The zone to convert to.

Returns:

DateTime

The date and time adjusted to the destination zone.

Exceptions: ArgumentNullException

Either time-zone argument is null.

ArgumentException

dateTime 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.

C#
public static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo destinationTimeZone)
Parameters:dateTimeDateTime

The value to convert.

destinationTimeZoneTimeZoneInfo

The time zone to convert to.

Returns:

DateTime

The date and time adjusted to the destination zone.

Exceptions: ArgumentNullException

destinationTimeZone is null.

ArgumentException

dateTime is an invalid local time.

Converts the represented instant to the destination zone while retaining it as a DateTimeOffset.

C#
public static DateTimeOffset ConvertTime(DateTimeOffset dateTimeOffset, TimeZoneInfo destinationTimeZone)
Parameters:dateTimeOffsetDateTimeOffset

The instant to convert.

destinationTimeZoneTimeZoneInfo

The time zone to convert to.

Returns:

DateTimeOffset

The instant with the destination zone's offset, clamped to the DateTimeOffset range if needed.

Exceptions: ArgumentNullException

destinationTimeZone is null.

Converts a value between system time zones identified by their IDs.

C#
public static DateTime ConvertTimeBySystemTimeZoneId(DateTime dateTime, string sourceTimeZoneId, string destinationTimeZoneId)
Parameters:dateTimeDateTime

The value to convert.

sourceTimeZoneIdstring

The ID of the source system time zone.

destinationTimeZoneIdstring

The ID of the destination system time zone.

Returns:

DateTime

The converted value.

Exceptions: ArgumentNullException

Either time-zone ID is null.

TimeZoneNotFoundException

Either ID does not identify a system time zone.

InvalidTimeZoneException

The data for a requested time zone is invalid.

SecurityException

Access to system time-zone data is denied.

ArgumentException

dateTime 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.

C#
public static DateTime ConvertTimeBySystemTimeZoneId(DateTime dateTime, string destinationTimeZoneId)
Parameters:dateTimeDateTime

The value to convert; UTC values use UTC as the source, and other values use the local zone.

destinationTimeZoneIdstring

The ID of the destination system time zone.

Returns:

DateTime

The converted value.

Exceptions: ArgumentNullException

destinationTimeZoneId is null.

TimeZoneNotFoundException

The destination ID does not identify a system time zone.

InvalidTimeZoneException

The system time-zone data is invalid.

SecurityException

Access to system time-zone data is denied.

ArgumentException

dateTime is an invalid local time.

Converts an instant to a system time zone identified by its ID.

C#
public static DateTimeOffset ConvertTimeBySystemTimeZoneId(DateTimeOffset dateTimeOffset, string destinationTimeZoneId)
Parameters:dateTimeOffsetDateTimeOffset

The instant to convert.

destinationTimeZoneIdstring

The ID of the destination system time zone.

Returns:

DateTimeOffset

The instant with the destination zone's offset.

Exceptions: ArgumentNullException

destinationTimeZoneId is null.

TimeZoneNotFoundException

The destination ID does not identify a system time zone.

InvalidTimeZoneException

The system time-zone data is invalid.

SecurityException

Access to system time-zone data is denied.

Converts a UTC value to the destination time zone.

C#
public static DateTime ConvertTimeFromUtc(DateTime dateTime, TimeZoneInfo destinationTimeZone)
Parameters:dateTimeDateTime

The value expressed in UTC.

destinationTimeZoneTimeZoneInfo

The destination time zone.

Returns:

DateTime

The converted value.

Exceptions: ArgumentNullException

destinationTimeZone is null.

ArgumentException

dateTime has local kind rather than UTC.

Converts a value from the supplied source time zone to UTC.

C#
public static DateTime ConvertTimeToUtc(DateTime dateTime, TimeZoneInfo sourceTimeZone)
Parameters:dateTimeDateTime

The value to convert.

sourceTimeZoneTimeZoneInfo

The zone in which dateTime is expressed.

Returns:

DateTime

The value expressed in UTC.

Exceptions: ArgumentNullException

sourceTimeZone is null.

ArgumentException

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.

C#
public static DateTime ConvertTimeToUtc(DateTime dateTime)
Parameters:dateTimeDateTime

The value to convert; an unspecified or local value is treated as local time.

Returns:

DateTime

The value expressed in UTC.

Exceptions: ArgumentException

dateTime is an invalid local time.

Creates a custom time zone from adjustment rules, optionally disabling their daylight-saving behavior.

C#
public static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string daylightDisplayName, TimeZoneInfo.AdjustmentRule[] adjustmentRules, bool disableDaylightSavingTime)
Parameters:idstring

The identifier for the custom zone.

baseUtcOffsetTimeSpan

The zone's standard offset from UTC.

displayNamestring

The name shown when the zone is displayed.

standardDisplayNamestring

The name used while standard time is in effect.

daylightDisplayNamestring

The 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.

disableDaylightSavingTimebool

If true, the zone ignores daylight-saving adjustments.

Returns:

TimeZoneInfo

A custom time zone configured with the supplied offset and rules.

Exceptions: ArgumentNullException

id is null.

ArgumentException

id is empty or the offset contains sub-minute precision.

ArgumentOutOfRangeException

baseUtcOffset is outside the supported UTC-offset range.

InvalidTimeZoneException

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.

C#
public static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string daylightDisplayName, TimeZoneInfo.AdjustmentRule[] adjustmentRules)
Parameters:idstring

The identifier for the custom zone.

baseUtcOffsetTimeSpan

The zone's standard offset from UTC.

displayNamestring

The name shown when the zone is displayed.

standardDisplayNamestring

The name used while standard time is in effect.

daylightDisplayNamestring

The 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:

TimeZoneInfo

A custom time zone configured with the supplied adjustment rules.

Exceptions: ArgumentNullException

id is null.

ArgumentException

id is empty or the offset contains sub-minute precision.

ArgumentOutOfRangeException

baseUtcOffset is outside the supported UTC-offset range.

InvalidTimeZoneException

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.

C#
public static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName)
Parameters:idstring

The identifier for the custom zone.

baseUtcOffsetTimeSpan

The zone's standard offset from UTC.

displayNamestring

The name shown when the zone is displayed.

standardDisplayNamestring

The name used while standard time is in effect.

Returns:

TimeZoneInfo

A custom time zone without daylight-saving transitions.

Exceptions: ArgumentNullException

id is null.

ArgumentException

id is empty or the offset contains sub-minute precision.

ArgumentOutOfRangeException

baseUtcOffset is outside the supported UTC-offset range.

Determines whether another zone has the same identifier and adjustment rules.

C#
public bool Equals(TimeZoneInfo other)
Parameters:otherTimeZoneInfo

The zone to compare with this instance.

Returns:

bool

true if the identifiers and rules match; otherwise, false.

Implements: IEquatable<TimeZoneInfo>.Equals(TimeZoneInfo)

Retrieves a system time zone by its identifier.

C#
public static TimeZoneInfo FindSystemTimeZoneById(string id)
Parameters:idstring

The system time-zone identifier; "UTC" resolves to Utc.

Returns:

TimeZoneInfo

The matching system time zone.

Exceptions: ArgumentNullException

id is null.

TimeZoneNotFoundException

No system time zone has the specified identifier.

InvalidTimeZoneException

The registry data for the requested zone is invalid.

SecurityException

Access to system time-zone data is denied.

Creates a time zone from the serialized representation produced by ToSerializedString().

C#
public static TimeZoneInfo FromSerializedString(string source)
Parameters:sourcestring

The serialized time-zone data.

Returns:

TimeZoneInfo

The time zone described by source.

Exceptions: ArgumentNullException

source is null.

ArgumentException

source is empty.

SerializationException

source is malformed or does not describe a valid time zone.

Gets a copy of the daylight-saving adjustment rules associated with this zone.

C#
public TimeZoneInfo.AdjustmentRule[] GetAdjustmentRules()
Returns:

AdjustmentRule[]

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.

C#
public TimeSpan[] GetAmbiguousTimeOffsets(DateTime dateTime)
Parameters:dateTimeDateTime

The potentially ambiguous wall-clock value.

Returns:

TimeSpan[]

The standard and daylight offsets that can represent the same local time.

Exceptions: ArgumentException

dateTime is not ambiguous in this zone.

Gets the two possible UTC offsets for the local time represented by an offset value in this zone.

C#
public TimeSpan[] GetAmbiguousTimeOffsets(DateTimeOffset dateTimeOffset)
Parameters:dateTimeOffsetDateTimeOffset

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: ArgumentException

dateTimeOffset does not map to an ambiguous local time in this zone.

Returns a hash code derived from the time-zone identifier.

C#
public override int GetHashCode()
Returns:

int

Overrides: object.GetHashCode()

Gets the system time zones as a read-only collection.

C#
[SecurityCritical]
public static ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones()
Returns:

ReadOnlyCollection<TimeZoneInfo>

A cached, read-only collection of the available system time zones.

Exceptions: SecurityException

Access to system time-zone data is denied.

Gets this zone's UTC offset for a date/time, applying the relevant daylight-saving rule.

C#
public TimeSpan GetUtcOffset(DateTime dateTime)
Parameters:dateTimeDateTime

The value whose offset is requested; UTC and local kinds are treated as instants, while an unspecified kind is treated as a wall-clock time in this zone.

Returns:

TimeSpan

The offset from UTC at the specified date/time.

Gets this zone's UTC offset at the instant represented by a DateTimeOffset.

C#
public TimeSpan GetUtcOffset(DateTimeOffset dateTimeOffset)
Parameters:dateTimeOffsetDateTimeOffset

The instant whose offset is requested.

Returns:

TimeSpan

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.

C#
public bool HasSameRules(TimeZoneInfo other)
Parameters:otherTimeZoneInfo

The zone to compare with this instance.

Returns:

bool

true if the base offsets and rules match; otherwise, false.

Exceptions: ArgumentNullException

other is null.

Determines whether a wall-clock value maps to two instants in this zone during a backward daylight-saving transition.

C#
public bool IsAmbiguousTime(DateTime dateTime)
Parameters:dateTimeDateTime

The value to examine.

Returns:

bool

true if the value has two possible UTC offsets; otherwise, false.

Determines whether the instant represented by a DateTimeOffset maps to an ambiguous local time in this zone.

C#
public bool IsAmbiguousTime(DateTimeOffset dateTimeOffset)
Parameters:dateTimeOffsetDateTimeOffset

The value to examine.

Returns:

bool

true if the converted local time has two possible UTC offsets; otherwise, false.

Determines whether a date/time falls within a daylight-saving adjustment period in this zone.

C#
public bool IsDaylightSavingTime(DateTime dateTime)
Parameters:dateTimeDateTime

The value to examine.

Returns:

bool

true if daylight-saving time applies; otherwise, false.

Determines whether daylight-saving time applies in this zone at the instant represented by a DateTimeOffset.

C#
public bool IsDaylightSavingTime(DateTimeOffset dateTimeOffset)
Parameters:dateTimeOffsetDateTimeOffset

The instant to examine.

Returns:

bool

true if daylight-saving time applies; otherwise, false.

Determines whether a wall-clock value falls in the gap created by a forward daylight-saving transition.

C#
public bool IsInvalidTime(DateTime dateTime)
Parameters:dateTimeDateTime

The value to examine; unspecified values are checked directly, while local values are checked only for the system local zone.

Returns:

bool

true if the value does not exist in this zone; otherwise, false.

Serializes this zone's identifier, display names, base offset, and adjustment rules.

C#
public string ToSerializedString()
Returns:

string

A string that can be parsed by FromSerializedString(string).

Returns the zone's DisplayName.

C#
public override string ToString()
Returns:

string

Overrides: object.ToString()