1 out of 6 rated this helpful - Rate this topic

TimeZoneInfo Class

Represents any time zone in the world.

System.Object
  System.TimeZoneInfo

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
[SerializableAttribute]
[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public sealed class TimeZoneInfo : IEquatable<TimeZoneInfo>, 
	ISerializable, IDeserializationCallback

The TimeZoneInfo type exposes the following members.

  Name Description
Public property BaseUtcOffset Gets the time difference between the current time zone's standard time and Coordinated Universal Time (UTC).
Public property DaylightName Gets the localized display name for the current time zone's daylight saving time.
Public property DisplayName Gets the localized general display name that represents the time zone.
Public property Id Gets the time zone identifier.
Public property Static member Local Gets a TimeZoneInfo object that represents the local time zone.
Public property StandardName Gets the localized display name for the time zone's standard time.
Public property SupportsDaylightSavingTime Gets a value indicating whether the time zone has any daylight saving time rules.
Public property Static member Utc Gets a TimeZoneInfo object that represents the Coordinated Universal Time (UTC) zone.
Top
  Name Description
Public method Static member ClearCachedData Clears cached time zone data.
Public method Static member ConvertTime(DateTime, TimeZoneInfo) Converts a time to the time in a particular time zone.
Public method Static member ConvertTime(DateTimeOffset, TimeZoneInfo) Converts a time to the time in a particular time zone.
Public method Static member ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo) Converts a time from one time zone to another.
Public method Static member ConvertTimeBySystemTimeZoneId(DateTime, String) Converts a time to the time in another time zone based on the time zone's identifier.
Public method Static member ConvertTimeBySystemTimeZoneId(DateTimeOffset, String) Converts a time to the time in another time zone based on the time zone's identifier.
Public method Static member ConvertTimeBySystemTimeZoneId(DateTime, String, String) Converts a time from one time zone to another based on time zone identifiers.
Public method Static member ConvertTimeFromUtc Converts a Coordinated Universal Time (UTC) to the time in a specified time zone.
Public method Static member ConvertTimeToUtc(DateTime) Converts the current date and time to Coordinated Universal Time (UTC).
Public method Static member ConvertTimeToUtc(DateTime, TimeZoneInfo) Converts the time in a specified time zone to Coordinated Universal Time (UTC).
Public method Static member CreateCustomTimeZone(String, TimeSpan, String, String) Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, and a standard time display name.
Public method Static member CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo.AdjustmentRule[]) Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, a standard time name, a daylight saving time name, and daylight saving time rules.
Public method Static member CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo.AdjustmentRule[], Boolean) Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, a standard time name, a daylight saving time name, daylight saving time rules, and a value that indicates whether the returned object reflects daylight saving time information.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public method Equals(TimeZoneInfo) Determines whether the current TimeZoneInfo object and another TimeZoneInfo object are equal.
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Static member FindSystemTimeZoneById Retrieves a TimeZoneInfo object from the registry based on its identifier.
Public method Static member FromSerializedString Deserializes a string to re-create an original serialized TimeZoneInfo object.
Public method GetAdjustmentRules Retrieves an array of TimeZoneInfo.AdjustmentRule objects that apply to the current TimeZoneInfo object.
Public method GetAmbiguousTimeOffsets(DateTime) Returns information about the possible dates and times that an ambiguous date and time can be mapped to.
Public method GetAmbiguousTimeOffsets(DateTimeOffset) Returns information about the possible dates and times that an ambiguous date and time can be mapped to.
Public method GetHashCode Serves as a hash function for hashing algorithms and data structures such as hash tables. (Overrides Object.GetHashCode().)
Public method Static member GetSystemTimeZones Returns a sorted collection of all the time zones about which information is available on the local system.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method GetUtcOffset(DateTime) Calculates the offset or difference between the time in this time zone and Coordinated Universal Time (UTC) for a particular date and time.
Public method GetUtcOffset(DateTimeOffset) Calculates the offset or difference between the time in this time zone and Coordinated Universal Time (UTC) for a particular date and time.
Public method HasSameRules Indicates whether the current object and another TimeZoneInfo object have the same adjustment rules.
Public method 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.
Public method 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.
Public method IsDaylightSavingTime(DateTime) Indicates whether a specified date and time falls in the range of daylight saving time for the time zone of the current TimeZoneInfo object.
Public method IsDaylightSavingTime(DateTimeOffset) Indicates whether a specified date and time falls in the range of daylight saving time for the time zone of the current TimeZoneInfo object.
Public method IsInvalidTime Indicates whether a particular date and time is invalid.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToSerializedString Converts the current TimeZoneInfo object to a serialized string.
Public method ToString Returns the current TimeZoneInfo object's display name. (Overrides Object.ToString().)
Top
  Name Description
Explicit interface implemetation Private method IDeserializationCallback.OnDeserialization Infrastructure. Runs when the deserialization of an object has been completed.
Explicit interface implemetation Private method ISerializable.GetObjectData Infrastructure. Populates a SerializationInfo object with the data needed to serialize the current TimeZoneInfo object.
Top

A time zone is a geographical region in which the same time is used.

The TimeZoneInfo class offers significant enhancements over the TimeZone class, which provides only limited functionality.

The TimeZone class recognizes only the local time zone, and can convert times between Coordinated Universal Time (UTC) and local time. A TimeZoneInfo object can represent any time zone, and methods of the TimeZoneInfo class can be used to convert the time in one time zone to the corresponding time in any other time zone. The members of the TimeZoneInfo class support the following operations:

  • Retrieving a time zone that is already defined by the operating system.

  • Enumerating the time zones that are available on a system.

  • Converting times between different time zones.

  • Creating a new time zone that is not already defined by the operating system.

  • Serializing a time zone for later retrieval.

Note Note

An instance of the TimeZoneInfo class is immutable. Once an object has been instantiated, its values cannot be modified.

You cannot instantiate a TimeZoneInfo object using the new keyword. Instead, you must call one of the static members of the TimeZoneInfo class shown in the following table.

Static member name

Description

CreateCustomTimeZone method

Creates a custom time zone from application-supplied data.

FindSystemTimeZoneById method

Instantiates a time zone defined in the system registry based on the zone's identifier.

FromSerializedString method

Deserializes a string value to re-create a previously serialized TimeZoneInfo object.

GetSystemTimeZones method

Returns an enumerable ReadOnlyCollection<T> of TimeZoneInfo objects that represents all time zones that are available on the local system.

Local property

Instantiates a TimeZoneInfo object that represents the local time zone.

Utc property

Instantiates a TimeZoneInfo object that represents the UTC zone.

You can use the CreateCustomTimeZone method to create a time zone that is not defined in the local system registry. You can then use the ToSerializedString property to save the time zone object's information as a string, which can be stored in some form that is accessible to the application. You can use the FromSerializedString method to convert a serialized string back to a TimeZoneInfo object.

Note Note

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: MayLeakOnAbort. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
3.5 to 4.0 upgradation issue

has TimeZoneInfo been changed from 3.5 to 4.0?

i ran a MS Build 3.5 project in 4.0 and got the following error:C:\Program Files\MSBuild\Microsoft\Windows Workflow Foundation\v3.5\Workflow.Targets(129):The type 'System.TimeZoneInfo' exists in both 'C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.core.dll' and 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll'

is it ok, if i use TimeZoneInfo of 4.0 instead of 3.5???

TimeZoneInfo in the .NET Framework 4

Although I can't reproduce the issue that you're having, it's almost certainly due to the fact that the TimeZoneInfo class has been type-forwarded from System.Core.dll (where it resides in the .NET Framework 3.5) to mscorlib.dll (where it resides in the .NET Framework 4).  Despite the change in location, the functionality of TimeZoneInfo in the two versions is the same. So if you can, you should convert your MSBuild project file for Visual Studio 2008 to an MSBuild project file for Visual Studio 2010.

I hope that this helps.

--Ron Petrusha
Common Language Runtime User Education
Microsoft Corporation

List of TimeZones
For an extensive list of timezones see the XML file here

https://skydrive.live.com/?cid=95e9849b11bde22f#cid=95E9849B11BDE22F&id=95E9849B11BDE22F!120

There is an error in the note about HostProtectionAttribute

"The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser)."

I believe that part about the URL in a browser is not correct.

Starting Applications from a Browser

Actually, it's correct. If you enter a URL to a document, such as file:///c:/temp/MySpreadsheet.xlsx, Internet Explorer will lauch the associated application, which will in turn open the document.

--Ron Petrusha
Common Language Runtime User Education
Microsoft Corporation

It works great but...
The class uses the Windows TimeZone infos which also correctly support the change in day light saving dates.

For the other versions of .Net, I created my own version of TimeZoneInfo at http://www.dupuis.me/node/7