From f29a477bcb4b079d8819a4274f4135d74a807efa Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 6 Mar 2024 20:12:38 -0800 Subject: [PATCH] update new vs. cached instance info for getsystemtimezonebyid method --- xml/System/TimeZoneInfo.xml | 2058 ++++++++++++++++++----------------- 1 file changed, 1030 insertions(+), 1028 deletions(-) diff --git a/xml/System/TimeZoneInfo.xml b/xml/System/TimeZoneInfo.xml index e9f410738d0..383ad9af4ff 100644 --- a/xml/System/TimeZoneInfo.xml +++ b/xml/System/TimeZoneInfo.xml @@ -87,41 +87,41 @@ Represents any time zone in the world. - class offers significant enhancements over the class, which provides only limited functionality. - - The class recognizes only the local time zone, and can convert times between Coordinated Universal Time (UTC) and local time. A object can represent any time zone, and methods of the 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 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] -> An instance of the class is immutable. Once an object has been instantiated, its values cannot be modified. - - You cannot instantiate a object using the `new` keyword. Instead, you must call one of the static members of the class shown in the following table. - -|Static member name|Description| -|------------------------|-----------------| -| method|Creates a custom time zone from application-supplied data.| -| method|Instantiates a time zone based on its identifier.| -| method|Deserializes a string value to re-create a previously serialized object.| -| method|Returns an enumerable of objects that represents all time zones that are available on the local system.| -| property|Instantiates a object that represents the local time zone.| -| property|Instantiates a object that represents the UTC zone.| - - You can use the method to create a time zone that is not defined in the local system registry on Windows systems or by the [ICU Library's Time Zone Data](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux or macOS. You can then use the 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 method to convert a serialized string back to a object. - + class offers significant enhancements over the class, which provides only limited functionality. + + The class recognizes only the local time zone, and can convert times between Coordinated Universal Time (UTC) and local time. A object can represent any time zone, and methods of the 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 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] +> An instance of the class is immutable. Once an object has been instantiated, its values cannot be modified. + + You cannot instantiate a object using the `new` keyword. Instead, you must call one of the static members of the class shown in the following table. + +|Static member name|Description| +|------------------------|-----------------| +| method|Creates a custom time zone from application-supplied data.| +| method|Instantiates a time zone based on its identifier.| +| method|Deserializes a string value to re-create a previously serialized object.| +| method|Returns an enumerable of objects that represents all time zones that are available on the local system.| +| property|Instantiates a object that represents the local time zone.| +| property|Instantiates a object that represents the UTC zone.| + + You can use the method to create a time zone that is not defined in the local system registry on Windows systems or by the [ICU Library's Time Zone Data](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux or macOS. You can then use the 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 method to convert a serialized string back to a object. + ]]> @@ -170,31 +170,31 @@ Gets the time difference between the current time zone's standard time and Coordinated Universal Time (UTC). An object that indicates the time difference between the current time zone's standard time and Coordinated Universal Time (UTC). - property can range from 14 hours (for a time zone that is 14 hours ahead of Coordinated Universal Time (UTC)) to -14 hours (for a time zone that is 14 hours behind UTC). Time zones that are ahead of UTC have a positive offset; time zones that are behind UTC have a negative offset. - - The value is represented as a whole number of minutes. It cannot include a fractional number of minutes. - -> [!NOTE] -> Because is a property of the object rather than the object, the class applies a single offset from UTC to all of a time zone's adjustments. To reflect a time zone that has modified its offset from UTC, you must create a new time zone using the method. - - The property differs from the method in the following ways: - -- The property returns the difference between UTC and the time zone's standard time; the method returns the difference between UTC and the time zone's time at a particular point in time. - -- The method reflects the application of any adjustment rules to the time zone; the property does not. - - - -## Examples - The following example uses the property to display the difference between the local time and Coordinated Universal Time (UTC). - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet1"::: - + property can range from 14 hours (for a time zone that is 14 hours ahead of Coordinated Universal Time (UTC)) to -14 hours (for a time zone that is 14 hours behind UTC). Time zones that are ahead of UTC have a positive offset; time zones that are behind UTC have a negative offset. + + The value is represented as a whole number of minutes. It cannot include a fractional number of minutes. + +> [!NOTE] +> Because is a property of the object rather than the object, the class applies a single offset from UTC to all of a time zone's adjustments. To reflect a time zone that has modified its offset from UTC, you must create a new time zone using the method. + + The property differs from the method in the following ways: + +- The property returns the difference between UTC and the time zone's standard time; the method returns the difference between UTC and the time zone's time at a particular point in time. + +- The method reflects the application of any adjustment rules to the time zone; the property does not. + + + +## Examples + The following example uses the property to display the difference between the local time and Coordinated Universal Time (UTC). + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet1"::: + ]]> @@ -240,19 +240,19 @@ Clears cached time zone data. - objects that are no longer references to or . For example, in the following code, the second call to the method throws an because the `local` variable is no longer considered equal to . - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ClearCachedData/System.TimeZone2.BestPractices.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ClearCachedData/System.TimeZone2.BestPractices.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.BestPractices/vb/System.TimeZone2.BestPractices.vb" id="Snippet1"::: - + objects that are no longer references to or . For example, in the following code, the second call to the method throws an because the `local` variable is no longer considered equal to . + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ClearCachedData/System.TimeZone2.BestPractices.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ClearCachedData/System.TimeZone2.BestPractices.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.BestPractices/vb/System.TimeZone2.BestPractices.vb" id="Snippet1"::: + ]]> @@ -321,42 +321,42 @@ Converts a time to the time in a particular time zone. The date and time in the destination time zone. - method applies any adjustment rules in effect in the `destinationTimeZone` time zone. - - This overload of the method determines the source time zone from the value of the `dateTime` parameter's property, as the following table shows. - -|Kind property value|Source time zone|Method behavior| -|-------------------------|----------------------|---------------------| -|||Converts the local time to the time in `destinationTimeZone`.| -|||Converts Coordinated Universal Time (UTC) to the time in `destinationTimeZone`.| -||Assumed to be .|Converts the local time to the time in `destinationTimeZone`.| - - The property of the returned value is set as shown in the following table. - -|Condition|Returned Kind property value| -|---------------|----------------------------------| -|The `destinationTimeZone` is .|| -|The `destinationTimeZone` is .|| -|All other date and time values and destination time zones.|| - - If the value of the `dateTime` parameter is an ambiguous local time, it is interpreted as a standard time. If the `dateTime` parameter is an invalid local time, this method throws an . - - If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. - - You can also convert to or from UTC by calling the and methods. - - - -## Examples - The following example converts an array of date and time values to times in the Eastern Time zone of the U.S. and Canada. It shows that the source time zone depends on the property of the source value. It also illustrates that the method takes time zone adjustments into account, because a time zone adjustment occurs in both the source and destination time zones at 2:00 A.M. on November 7, 2010. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/converttime1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/converttime1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.timezoneinfo.converttime/vb/converttime1.vb" id="Snippet1"::: - + method applies any adjustment rules in effect in the `destinationTimeZone` time zone. + + This overload of the method determines the source time zone from the value of the `dateTime` parameter's property, as the following table shows. + +|Kind property value|Source time zone|Method behavior| +|-------------------------|----------------------|---------------------| +|||Converts the local time to the time in `destinationTimeZone`.| +|||Converts Coordinated Universal Time (UTC) to the time in `destinationTimeZone`.| +||Assumed to be .|Converts the local time to the time in `destinationTimeZone`.| + + The property of the returned value is set as shown in the following table. + +|Condition|Returned Kind property value| +|---------------|----------------------------------| +|The `destinationTimeZone` is .|| +|The `destinationTimeZone` is .|| +|All other date and time values and destination time zones.|| + + If the value of the `dateTime` parameter is an ambiguous local time, it is interpreted as a standard time. If the `dateTime` parameter is an invalid local time, this method throws an . + + If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. + + You can also convert to or from UTC by calling the and methods. + + + +## Examples + The following example converts an array of date and time values to times in the Eastern Time zone of the U.S. and Canada. It shows that the source time zone depends on the property of the source value. It also illustrates that the method takes time zone adjustments into account, because a time zone adjustment occurs in both the source and destination time zones at 2:00 A.M. on November 7, 2010. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/converttime1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/converttime1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.timezoneinfo.converttime/vb/converttime1.vb" id="Snippet1"::: + ]]> The value of the parameter represents an invalid time. @@ -414,26 +414,26 @@ Converts a time to the time in a particular time zone. The date and time in the destination time zone. - method applies any adjustment rules in effect in the `destinationTimeZone` time zone. - - This overload differs from the other overloads of the method by accepting a value as its first parameter. This identifies the date and time as an offset from Coordinated Universal Time (UTC) rather than as the date and time in a particular time zone. As a result, the `dateTimeOffset` parameter cannot represent either an ambiguous time or an invalid time. - - In converting the `dateTimeOffset` value to the time in the destination time zone, this method takes into account any adjustment rules in effect in the destination time zone. - - If the conversion of `dateTimeOffset` results in a date and time value that is earlier than or later than , this method returns or , respectively. - - - -## Examples - The following example converts an array of values to times in the Eastern Time zone of the U.S. and Canada. It illustrates that the method takes time zone adjustments into account, because a time zone adjustment occurs in both the source and destination time zones at 2:00 A.M. on November 7, 2010. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/converttime2.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/converttime2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.timezoneinfo.converttime/vb/converttime2.vb" id="Snippet2"::: - + method applies any adjustment rules in effect in the `destinationTimeZone` time zone. + + This overload differs from the other overloads of the method by accepting a value as its first parameter. This identifies the date and time as an offset from Coordinated Universal Time (UTC) rather than as the date and time in a particular time zone. As a result, the `dateTimeOffset` parameter cannot represent either an ambiguous time or an invalid time. + + In converting the `dateTimeOffset` value to the time in the destination time zone, this method takes into account any adjustment rules in effect in the destination time zone. + + If the conversion of `dateTimeOffset` results in a date and time value that is earlier than or later than , this method returns or , respectively. + + + +## Examples + The following example converts an array of values to times in the Eastern Time zone of the U.S. and Canada. It illustrates that the method takes time zone adjustments into account, because a time zone adjustment occurs in both the source and destination time zones at 2:00 A.M. on November 7, 2010. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/converttime2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/converttime2.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.timezoneinfo.converttime/vb/converttime2.vb" id="Snippet2"::: + ]]> The value of the parameter is . @@ -490,61 +490,61 @@ Converts a time from one time zone to another. The date and time in the destination time zone that corresponds to the parameter in the source time zone. - method applies any adjustment rules in effect in the `destinationTimeZone` time zone. - - The value of the property of the `dateTime` parameter must correspond to the `sourceTimeZone` parameter, as the following table shows. - -|DateTime.Kind value|sourceTimeZone value|Method behavior| -|-------------------------|--------------------------|---------------------| -||Equals .|Converts `dateTime` to the destination time zone's time.| -||Does not equal .|Throws an .| -||Equals .|Converts `dateTime` to the destination time zone's time.| -||Does not equal .|Throws an .| -||Any.|Converts `dateTime` to the destination time zone's time.| - - You can also convert to or from Coordinated Universal Time (UTC) by calling the and methods. - - The property of the returned value is set as shown in the following table. - -|Condition|Returned Kind property value| -|---------------|----------------------------------| -|The `destinationTimeZone` argument is .|| -|The `destinationTimeZone` argument is .|| -|All other date and time values, source time zones, and destination time zones.|| - - If the value of the `dateTime` parameter is an ambiguous time in the source time zone, it is interpreted as a standard time. If the `dateTime` parameter is an invalid time in the source time zone, this method throws an . - - If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. - - The method throws an exception if the property of the `dateTime` argument is but the `sourceTimeZone` argument is not . To determine whether the source time zone is the local time zone or the universal time zone, the method tests for reference equality instead of testing for value equality with the method. Note that objects that represent the local time zone and that are retrieved by calling the method do not have referential equality with . Furthermore, objects that represent the local or universal time zone and that are retrieved by iterating the collection returned by the method do not have referential equality with or . As an alternative, you can call the method. - - - -## Examples - The following example illustrates the use of the method to convert from Hawaiian Standard Time to local time. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.cs" id="Snippet9"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Concepts/VB/TimeZone2Concepts.vb" id="Snippet9"::: - + method applies any adjustment rules in effect in the `destinationTimeZone` time zone. + + The value of the property of the `dateTime` parameter must correspond to the `sourceTimeZone` parameter, as the following table shows. + +|DateTime.Kind value|sourceTimeZone value|Method behavior| +|-------------------------|--------------------------|---------------------| +||Equals .|Converts `dateTime` to the destination time zone's time.| +||Does not equal .|Throws an .| +||Equals .|Converts `dateTime` to the destination time zone's time.| +||Does not equal .|Throws an .| +||Any.|Converts `dateTime` to the destination time zone's time.| + + You can also convert to or from Coordinated Universal Time (UTC) by calling the and methods. + + The property of the returned value is set as shown in the following table. + +|Condition|Returned Kind property value| +|---------------|----------------------------------| +|The `destinationTimeZone` argument is .|| +|The `destinationTimeZone` argument is .|| +|All other date and time values, source time zones, and destination time zones.|| + + If the value of the `dateTime` parameter is an ambiguous time in the source time zone, it is interpreted as a standard time. If the `dateTime` parameter is an invalid time in the source time zone, this method throws an . + + If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. + + The method throws an exception if the property of the `dateTime` argument is but the `sourceTimeZone` argument is not . To determine whether the source time zone is the local time zone or the universal time zone, the method tests for reference equality instead of testing for value equality with the method. Note that objects that represent the local time zone and that are retrieved by calling the method do not have referential equality with . Furthermore, objects that represent the local or universal time zone and that are retrieved by iterating the collection returned by the method do not have referential equality with or . As an alternative, you can call the method. + + + +## Examples + The following example illustrates the use of the method to convert from Hawaiian Standard Time to local time. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.fs" id="Snippet9"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Concepts/VB/TimeZone2Concepts.vb" id="Snippet9"::: + ]]> - The property of the parameter is , but the parameter does not equal . - - -or- - - The property of the parameter is , but the parameter does not equal . - - -or- - + The property of the parameter is , but the parameter does not equal . + + -or- + + The property of the parameter is , but the parameter does not equal . + + -or- + The parameter is an invalid time (that is, it represents a time that does not exist because of a time zone's adjustment rules). - The parameter is . - - -or- - + The parameter is . + + -or- + The parameter is . Converting Times Between Time Zones @@ -607,34 +607,34 @@ Converts a time to the time in another time zone based on the time zone's identifier. The date and time in the destination time zone. - method applies any adjustment rules in effect in the `destinationTimeZoneId` time zone. - - This overload is largely identical to calling the method, except that it allows you to specify the destination time zone by its identifier rather than by an object reference. This method is most useful when you must convert a time without retrieving the time zone object that corresponds to it and you do not need to know whether the converted time is standard or daylight saving time. - - The method determines the source time zone from the value of the `dateTime` parameter's property, as the following table shows. - -|Kind property value|Source time zone|Method behavior| -|-------------------------|----------------------|---------------------| -|||Converts the local time to the time in `destinationTimeZone`.| -|||Converts Coordinated Universal Time (UTC) to the time in `destinationTimeZone`.| -||Assumed to be .|Converts the local time to the time in `destinationTimeZone`.| - - The property of the returned value is set as shown in the following table. - -|Condition|Returned Kind property value| -|---------------|----------------------------------| -|The `destinationTimeZone` is `TimeZoneInfo.Utc.Id`.|| -|Any other `destinationTimeZone` value.|| - - If the value of the `dateTime` parameter is an ambiguous local time, it is interpreted as a standard time. If the `dateTime` parameter is an invalid local time, this method throws an . - - If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. - - This method retrieves information on the time zone whose identifier is specified by the `destinationTimeZoneId` parameter from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. It cannot retrieve a time zone object that is created using the method. The `destinationTimeZoneId` parameter must correspond exactly to the time zone's identifier in length, but not in case, for a successful match to occur; that is, the comparison of `destinationTimeZoneId` with time zone identifiers is case-insensitive. - + method applies any adjustment rules in effect in the `destinationTimeZoneId` time zone. + + This overload is largely identical to calling the method, except that it allows you to specify the destination time zone by its identifier rather than by an object reference. This method is most useful when you must convert a time without retrieving the time zone object that corresponds to it and you do not need to know whether the converted time is standard or daylight saving time. + + The method determines the source time zone from the value of the `dateTime` parameter's property, as the following table shows. + +|Kind property value|Source time zone|Method behavior| +|-------------------------|----------------------|---------------------| +|||Converts the local time to the time in `destinationTimeZone`.| +|||Converts Coordinated Universal Time (UTC) to the time in `destinationTimeZone`.| +||Assumed to be .|Converts the local time to the time in `destinationTimeZone`.| + + The property of the returned value is set as shown in the following table. + +|Condition|Returned Kind property value| +|---------------|----------------------------------| +|The `destinationTimeZone` is `TimeZoneInfo.Utc.Id`.|| +|Any other `destinationTimeZone` value.|| + + If the value of the `dateTime` parameter is an ambiguous local time, it is interpreted as a standard time. If the `dateTime` parameter is an invalid local time, this method throws an . + + If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. + + This method retrieves information on the time zone whose identifier is specified by the `destinationTimeZoneId` parameter from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. It cannot retrieve a time zone object that is created using the method. The `destinationTimeZoneId` parameter must correspond exactly to the time zone's identifier in length, but not in case, for a successful match to occur; that is, the comparison of `destinationTimeZoneId` with time zone identifiers is case-insensitive. + ]]> @@ -691,21 +691,21 @@ Converts a time to the time in another time zone based on the time zone's identifier. The date and time in the destination time zone. - method applies any adjustment rules in effect in the `destinationTimeZoneId` time zone. - - This overload is identical to calling the method, except that it allows you to specify the destination time zone by its identifier rather than by an object reference. This method is most useful when you must convert a time without retrieving the time zone object that corresponds to it and you do not need to know whether the converted time is standard or daylight saving time. - - Because the `dateTimeOffset` parameter represents a date and time together with that time's offset from Coordinated Universal Time (UTC), it cannot represent either an ambiguous time or an invalid time. - - This method retrieves the time zone whose identifier is specified by the `destinationTimeZoneId` parameter from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. It cannot retrieve a time zone object that is created using the method. The `destinationTimeZoneId` parameter must correspond exactly to the time zone's identifier in length, but not in case, for a successful match to occur; that is, the comparison of `destinationTimeZoneId` with time zone identifiers is case-insensitive. - - In converting the `dateTimeOffset` value to the time in the destination time zone, the method takes into account any adjustment rules in effect in the destination time zone. - - If the conversion of `dateTimeOffset` results in a date and time value that is earlier than or later than , this method returns or , respectively. - + method applies any adjustment rules in effect in the `destinationTimeZoneId` time zone. + + This overload is identical to calling the method, except that it allows you to specify the destination time zone by its identifier rather than by an object reference. This method is most useful when you must convert a time without retrieving the time zone object that corresponds to it and you do not need to know whether the converted time is standard or daylight saving time. + + Because the `dateTimeOffset` parameter represents a date and time together with that time's offset from Coordinated Universal Time (UTC), it cannot represent either an ambiguous time or an invalid time. + + This method retrieves the time zone whose identifier is specified by the `destinationTimeZoneId` parameter from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. It cannot retrieve a time zone object that is created using the method. The `destinationTimeZoneId` parameter must correspond exactly to the time zone's identifier in length, but not in case, for a successful match to occur; that is, the comparison of `destinationTimeZoneId` with time zone identifiers is case-insensitive. + + In converting the `dateTimeOffset` value to the time in the destination time zone, the method takes into account any adjustment rules in effect in the destination time zone. + + If the conversion of `dateTimeOffset` results in a date and time value that is earlier than or later than , this method returns or , respectively. + ]]> @@ -764,59 +764,59 @@ Converts a time from one time zone to another based on time zone identifiers. The date and time in the destination time zone that corresponds to the parameter in the source time zone. - method applies any adjustment rules in effect in the `destinationTimeZoneId` time zone. - - Although it is similar to the method, you can use to specify the source and destination time zones using their identifiers instead of their objects. This method is most useful when you must convert a time without retrieving the time zone object that corresponds to it and you do not need to know whether the converted time is standard or daylight saving time. - - This method retrieves the time zones whose identifiers are the `sourceTimeZoneId` and `destinationTimeZoneId` parameters from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. It cannot retrieve time zone objects that are created using the method. - - The value of the property of the `dateTime` parameter must correspond to the `sourceTimeZoneId` parameter, as the following table shows. - -|DateTime.Kind value|sourceTimeZone value|Method behavior| -|-------------------------|--------------------------|---------------------| -||Equals `TimeZoneInfo.Utc.Id`.|Converts `dateTime` to the destination time zone's time.| -||Does not equal `TimeZoneInfo.Utc.Id`.|Throws an .| -||Equals `TimeZoneInfo.Local.Id`.|Converts `dateTime` to the destination time zone's time.| -||Does not equal `TimeZoneInfo.Local.Id`.|Throws an .| -||Any.|Converts `dateTime` to the destination time zone's time.| - - Because it relies on calls to the method, the method performs a case-insensitive search to locate the time zones that correspond to `sourceTimeZoneId` and `destinationTimeZoneId`. - - If the value of the `dateTime` parameter is an ambiguous time in the source time zone, it is interpreted as a standard time. If the `dateTime` parameter is an invalid time in the source time zone, this method throws an . - - The property of the returned value is set to unless the destination time zone is Coordinated Universal Time (UTC), in which case it is set to . - - - -## Examples - The following example uses the method to display the time that corresponds to the local system time in eight cities of the world. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/System.TimeZone2.Conversions.vb" id="Snippet3"::: - + method applies any adjustment rules in effect in the `destinationTimeZoneId` time zone. + + Although it is similar to the method, you can use to specify the source and destination time zones using their identifiers instead of their objects. This method is most useful when you must convert a time without retrieving the time zone object that corresponds to it and you do not need to know whether the converted time is standard or daylight saving time. + + This method retrieves the time zones whose identifiers are the `sourceTimeZoneId` and `destinationTimeZoneId` parameters from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. It cannot retrieve time zone objects that are created using the method. + + The value of the property of the `dateTime` parameter must correspond to the `sourceTimeZoneId` parameter, as the following table shows. + +|DateTime.Kind value|sourceTimeZone value|Method behavior| +|-------------------------|--------------------------|---------------------| +||Equals `TimeZoneInfo.Utc.Id`.|Converts `dateTime` to the destination time zone's time.| +||Does not equal `TimeZoneInfo.Utc.Id`.|Throws an .| +||Equals `TimeZoneInfo.Local.Id`.|Converts `dateTime` to the destination time zone's time.| +||Does not equal `TimeZoneInfo.Local.Id`.|Throws an .| +||Any.|Converts `dateTime` to the destination time zone's time.| + + Because it relies on calls to the method, the method performs a case-insensitive search to locate the time zones that correspond to `sourceTimeZoneId` and `destinationTimeZoneId`. + + If the value of the `dateTime` parameter is an ambiguous time in the source time zone, it is interpreted as a standard time. If the `dateTime` parameter is an invalid time in the source time zone, this method throws an . + + The property of the returned value is set to unless the destination time zone is Coordinated Universal Time (UTC), in which case it is set to . + + + +## Examples + The following example uses the method to display the time that corresponds to the local system time in eight cities of the world. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/System.TimeZone2.Conversions.vb" id="Snippet3"::: + ]]> - The property of the parameter does not correspond to the source time zone. - - -or- - + The property of the parameter does not correspond to the source time zone. + + -or- + is an invalid time in the source time zone. - is . - - -or- - + is . + + -or- + is . The time zone identifiers were found, but the registry data is corrupted. The user does not have the permissions required to read from the registry keys that hold time zone data. - The identifier was not found on the local system. - - -or- - + The identifier was not found on the local system. + + -or- + The identifier was not found on the local system. Converting Times Between Time Zones @@ -867,29 +867,29 @@ Converts a Coordinated Universal Time (UTC) to the time in a specified time zone. The date and time in the destination time zone. Its property is if is ; otherwise, its property is . - method applies any adjustment rules in effect in the `destinationTimeZone` time zone. - - The precise behavior of this method depends on the value of the property of the `dateTime` parameter, as the following table shows. - -|DateTime.Kind property|Conversion| -|----------------------------|----------------| -||Throws an .| -| or |Converts from Coordinated Universal Time (UTC).| - - If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. - - - -## Examples - The following example converts Coordinated Universal Time (UTC) to Central Time. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.cs" id="Snippet8"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Concepts/VB/TimeZone2Concepts.vb" id="Snippet8"::: - + method applies any adjustment rules in effect in the `destinationTimeZone` time zone. + + The precise behavior of this method depends on the value of the property of the `dateTime` parameter, as the following table shows. + +|DateTime.Kind property|Conversion| +|----------------------------|----------------| +||Throws an .| +| or |Converts from Coordinated Universal Time (UTC).| + + If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. + + + +## Examples + The following example converts Coordinated Universal Time (UTC) to Central Time. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.fs" id="Snippet8"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Concepts/VB/TimeZone2Concepts.vb" id="Snippet8"::: + ]]> The property of is . @@ -953,33 +953,33 @@ Converts the specified date and time to Coordinated Universal Time (UTC). The Coordinated Universal Time (UTC) that corresponds to the parameter. The value's property is always set to . - property of the `dateTime` parameter, as the following table shows. - -|DateTime.Kind property|Conversion| -|----------------------------|----------------| -||Converts from local time to Coordinated Universal Time (UTC).| -||Assumes `dateTime` is local time and converts from local time to UTC.| -||Returns `dateTime` unchanged.| - - If `dateTime` corresponds to an ambiguous local time, this method assumes that it is standard local time. If `dateTime` corresponds to an invalid local time, the method throws an . - -> [!NOTE] -> If the current computer's local time zone includes multiple adjustment rules, this overload of the method can return results that differ from the and methods. always applies the current adjustment rule to time zone conversion, whether or not `dateTime` lies within its date range. And when executing on .NET Framework 3.5, also applies the current adjustment rule to time zone conversion, whether or not `dateTime` lies within its date range. - - If the UTC equivalent of `dateTime` is earlier than or later that , this method returns or , respectively. - - - -## Examples - The following example illustrates the conversion of time values whose property is , , and , respectively. It also illustrates the conversion of ambiguous and invalid times. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/System.TimeZone2.Conversions.vb" id="Snippet1"::: - + property of the `dateTime` parameter, as the following table shows. + +|DateTime.Kind property|Conversion| +|----------------------------|----------------| +||Converts from local time to Coordinated Universal Time (UTC).| +||Assumes `dateTime` is local time and converts from local time to UTC.| +||Returns `dateTime` unchanged.| + + If `dateTime` corresponds to an ambiguous local time, this method assumes that it is standard local time. If `dateTime` corresponds to an invalid local time, the method throws an . + +> [!NOTE] +> If the current computer's local time zone includes multiple adjustment rules, this overload of the method can return results that differ from the and methods. always applies the current adjustment rule to time zone conversion, whether or not `dateTime` lies within its date range. And when executing on .NET Framework 3.5, also applies the current adjustment rule to time zone conversion, whether or not `dateTime` lies within its date range. + + If the UTC equivalent of `dateTime` is earlier than or later that , this method returns or , respectively. + + + +## Examples + The following example illustrates the conversion of time values whose property is , , and , respectively. It also illustrates the conversion of ambiguous and invalid times. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/System.TimeZone2.Conversions.vb" id="Snippet1"::: + ]]> @@ -1035,35 +1035,35 @@ Converts the time in a specified time zone to Coordinated Universal Time (UTC). The Coordinated Universal Time (UTC) that corresponds to the parameter. The object's property is always set to . - property of the `dateTime` parameter equals and the `sourceTimeZone` parameter equals , this method returns `dateTime` without performing any conversion. - - If `dateTime` corresponds to an ambiguous time, this method assumes that it is the standard time of the source time zone. If `dateTime` corresponds to an invalid time, this method throws an . - - If the Coordinated Universal Time (UTC) equivalent of `dateTime` is earlier than or later that , this method returns or , respectively. - - - -## Examples - The following example retrieves the current date from the local system and converts it to Coordinated Universal Time (UTC), then converts it to Tokyo Standard Time, and finally converts from Tokyo Standard Time back to UTC. Note that the two UTC times are identical. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/convertdt2.vb" id="Snippet2"::: - + property of the `dateTime` parameter equals and the `sourceTimeZone` parameter equals , this method returns `dateTime` without performing any conversion. + + If `dateTime` corresponds to an ambiguous time, this method assumes that it is the standard time of the source time zone. If `dateTime` corresponds to an invalid time, this method throws an . + + If the Coordinated Universal Time (UTC) equivalent of `dateTime` is earlier than or later that , this method returns or , respectively. + + + +## Examples + The following example retrieves the current date from the local system and converts it to Coordinated Universal Time (UTC), then converts it to Tokyo Standard Time, and finally converts from Tokyo Standard Time back to UTC. Note that the two UTC times are identical. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/convertdt2.vb" id="Snippet2"::: + ]]> - . is and does not equal . - - -or- - - . is and does not equal . - - -or- - + . is and does not equal . + + -or- + + . is and does not equal . + + -or- + returns . is . @@ -1145,44 +1145,44 @@ 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. The new time zone. - method is suitable for creating a time zone that has no adjustments (that is, a time zone that does not support daylight saving time). To define a time zone that includes adjustments for daylight saving time, use either the or the method. - - The following table shows the relationship between the parameters that are provided to the method and the properties of the object that are returned by the method call. - -|CreateCustomTimeZone parameter|TimeZoneInfo property| -|------------------------------------|---------------------------| -|`id`|| -|`baseUtcOffset`|| -|`displayName`|| -|`standardDisplayName`|| - - Typically, the time zone's standard time name and its identifier are the same. However, the length of the time zone's identifier should not exceed 32 characters. The string passed to the `displayName` parameter follows a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. This is followed by a string that identifies the time zone itself, or one or more of the cities, regions, or countries in the time zone, or both. For example: - -``` -(GMT+02:00) Athens, Beirut, Istanbul, Minsk -(GMT-02:00) Mid-Atlantic -(GMT-07:00) Mountain Time (US & Canada) -``` - - - -## Examples - The following example creates a custom time zone for the Mawson and Holme Bay regions of Antarctica. It then displays the result of converting the local time to the time in the new time zone. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet1"::: - + method is suitable for creating a time zone that has no adjustments (that is, a time zone that does not support daylight saving time). To define a time zone that includes adjustments for daylight saving time, use either the or the method. + + The following table shows the relationship between the parameters that are provided to the method and the properties of the object that are returned by the method call. + +|CreateCustomTimeZone parameter|TimeZoneInfo property| +|------------------------------------|---------------------------| +|`id`|| +|`baseUtcOffset`|| +|`displayName`|| +|`standardDisplayName`|| + + Typically, the time zone's standard time name and its identifier are the same. However, the length of the time zone's identifier should not exceed 32 characters. The string passed to the `displayName` parameter follows a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. This is followed by a string that identifies the time zone itself, or one or more of the cities, regions, or countries in the time zone, or both. For example: + +``` +(GMT+02:00) Athens, Beirut, Istanbul, Minsk +(GMT-02:00) Mid-Atlantic +(GMT-07:00) Mountain Time (US & Canada) +``` + + + +## Examples + The following example creates a custom time zone for the Mawson and Holme Bay regions of Antarctica. It then displays the result of converting the local time to the time in the new time zone. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet1"::: + ]]> The parameter is . - The parameter is an empty string (""). - - -or- - + The parameter is an empty string (""). + + -or- + The parameter does not represent a whole number of minutes. The parameter is greater than 14 hours or less than -14 hours. How to: Create Time Zones Without Adjustment Rules @@ -1263,74 +1263,74 @@ 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. A object that represents the new time zone. - method is suitable for creating a time zone that supports daylight saving time. To define a time zone that does not support daylight saving time, use either the or the method. - - The following table shows the relationship between the parameters that are provided to the method and the members of the object that are returned by the method call. - -|CreateCustomTimeZone parameter|TimeZoneInfo member| -|------------------------------------|-------------------------| -|`id`|| -|`baseUtcOffset`|| -|`displayName`|| -|`standardDisplayName`|| -|`daylightDisplayName`|| -|`adjustmentRules`|An array of objects returned by the method.| - - Typically, the time zone's standard time name and its identifier are the same. However, the length of the time zone's identifier should not exceed 32 characters. The string passed to the `displayName` parameter follows a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. This is followed by a string that identifies the time zone itself, or one or more of the cities, regions, or countries in the time zone, or both. For example: - -``` -(GMT+02:00) Athens, Beirut, Istanbul, Minsk -(GMT-02:00) Mid-Atlantic -(GMT-07:00) Mountain Time (US & Canada) -``` - - The `baseUtcOffset` parameter defines the custom time zone's offset from Coordinated Universal Time (UTC) for all of the time zone's adjustment rules. In other words, the object model assumes that the time zone's offset from UTC is constant throughout the life of the time zone, and exists independent of particular adjustment rules. To reflect a time zone that has changed its offset from UTC, you must create a new time zone object. - - A time zone's adjustment rules are defined by doing the following: - -1. Calling either the or the method to define the starting and ending transition time for each adjustment rule. - -2. Calling the method for each adjustment rule. - -3. Assigning the adjustment rules to an array that can be passed as the `adjustmentRules` parameter. - - - -## Examples - The following example creates a custom time zone for the Palmer station and Anvers Island in Antarctica. It then converts the local time to the time in the new time zone and displays the result. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet2"::: - + method is suitable for creating a time zone that supports daylight saving time. To define a time zone that does not support daylight saving time, use either the or the method. + + The following table shows the relationship between the parameters that are provided to the method and the members of the object that are returned by the method call. + +|CreateCustomTimeZone parameter|TimeZoneInfo member| +|------------------------------------|-------------------------| +|`id`|| +|`baseUtcOffset`|| +|`displayName`|| +|`standardDisplayName`|| +|`daylightDisplayName`|| +|`adjustmentRules`|An array of objects returned by the method.| + + Typically, the time zone's standard time name and its identifier are the same. However, the length of the time zone's identifier should not exceed 32 characters. The string passed to the `displayName` parameter follows a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. This is followed by a string that identifies the time zone itself, or one or more of the cities, regions, or countries in the time zone, or both. For example: + +``` +(GMT+02:00) Athens, Beirut, Istanbul, Minsk +(GMT-02:00) Mid-Atlantic +(GMT-07:00) Mountain Time (US & Canada) +``` + + The `baseUtcOffset` parameter defines the custom time zone's offset from Coordinated Universal Time (UTC) for all of the time zone's adjustment rules. In other words, the object model assumes that the time zone's offset from UTC is constant throughout the life of the time zone, and exists independent of particular adjustment rules. To reflect a time zone that has changed its offset from UTC, you must create a new time zone object. + + A time zone's adjustment rules are defined by doing the following: + +1. Calling either the or the method to define the starting and ending transition time for each adjustment rule. + +2. Calling the method for each adjustment rule. + +3. Assigning the adjustment rules to an array that can be passed as the `adjustmentRules` parameter. + + + +## Examples + The following example creates a custom time zone for the Palmer station and Anvers Island in Antarctica. It then converts the local time to the time in the new time zone and displays the result. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet2"::: + ]]> The parameter is . - The parameter is an empty string (""). - - -or- - + The parameter is an empty string (""). + + -or- + The parameter does not represent a whole number of minutes. The parameter is greater than 14 hours or less than -14 hours. - The adjustment rules specified in the parameter overlap. - - -or- - - The adjustment rules specified in the parameter are not in chronological order. - - -or- - - One or more elements in are . - - -or- - - A date can have multiple adjustment rules applied to it. - - -or- - + The adjustment rules specified in the parameter overlap. + + -or- + + The adjustment rules specified in the parameter are not in chronological order. + + -or- + + One or more elements in are . + + -or- + + A date can have multiple adjustment rules applied to it. + + -or- + The sum of the parameter and the value of one or more objects in the array is greater than 14 hours or less than -14 hours. How to: Create Time Zones with Adjustment Rules @@ -1413,75 +1413,75 @@ 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. The new time zone. If the parameter is , the returned object has no daylight saving time data. - method to create a custom time zone whose support for daylight saving time can be determined by conditions at run time. - - The following table shows the relationship between the parameters that are provided to the method and the members of the object that are returned by the method call. - -|CreateCustomTimeZone parameter|TimeZoneInfo property| -|------------------------------------|---------------------------| -|`id`|| -|`baseUtcOffset`|| -|`displayName`|| -|`standardDisplayName`|| -|`daylightDisplayName`| if `disableDaylightSavingTime` is `false`; if `disableDaylightSavingTime` is `true`.| -|`adjustmentRules`|An array of objects returned by the method if `disableDaylightSavingTime` is `false`; an empty array returned by the method if `disableDaylightSavingTime` is `true`.| -|`disableDaylightSavingTime`|Not .| - - Typically, the time zone's standard time name and its identifier are the same. However, the length of the time zone's identifier should not exceed 32 characters. The string passed to the `displayName` parameter follows a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. This is followed by a string that identifies the time zone itself, or one or more of the cities, regions, or countries in the time zone, or both. For example: - -``` -(GMT+02:00) Athens, Beirut, Istanbul, Minsk -(GMT-02:00) Mid-Atlantic -(GMT-07:00) Mountain Time (US & Canada) -``` - - A time zone's adjustment rules are defined by doing the following: - -1. Calling either the or the method to define the starting and ending transition rules for each adjustment rule. - -2. Calling the method for each adjustment rule. - -3. Assigning the adjustment rules to an array that can be passed as the `adjustmentRules` parameter. - - If `disableDaylightSavingTime` parameter is `false`, the operation of this method is identical to the overload. If `disableDaylightSavingTime` is `true`, the returned object includes no adjustment rules and a property whose value is an empty string. - - - -## Examples - The following example creates a custom time zone for the Palmer station and Anvers Island in Antarctica. It sets the `disableDaylightSavingTime` parameter in the call to the method to `true`. It then displays the new time zone's daylight saving time name, if one is present, and the number of adjustment rules to confirm that the new time zone has no daylight saving time information. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" interactive="try-dotnet-method" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet3"::: - + method to create a custom time zone whose support for daylight saving time can be determined by conditions at run time. + + The following table shows the relationship between the parameters that are provided to the method and the members of the object that are returned by the method call. + +|CreateCustomTimeZone parameter|TimeZoneInfo property| +|------------------------------------|---------------------------| +|`id`|| +|`baseUtcOffset`|| +|`displayName`|| +|`standardDisplayName`|| +|`daylightDisplayName`| if `disableDaylightSavingTime` is `false`; if `disableDaylightSavingTime` is `true`.| +|`adjustmentRules`|An array of objects returned by the method if `disableDaylightSavingTime` is `false`; an empty array returned by the method if `disableDaylightSavingTime` is `true`.| +|`disableDaylightSavingTime`|Not .| + + Typically, the time zone's standard time name and its identifier are the same. However, the length of the time zone's identifier should not exceed 32 characters. The string passed to the `displayName` parameter follows a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. This is followed by a string that identifies the time zone itself, or one or more of the cities, regions, or countries in the time zone, or both. For example: + +``` +(GMT+02:00) Athens, Beirut, Istanbul, Minsk +(GMT-02:00) Mid-Atlantic +(GMT-07:00) Mountain Time (US & Canada) +``` + + A time zone's adjustment rules are defined by doing the following: + +1. Calling either the or the method to define the starting and ending transition rules for each adjustment rule. + +2. Calling the method for each adjustment rule. + +3. Assigning the adjustment rules to an array that can be passed as the `adjustmentRules` parameter. + + If `disableDaylightSavingTime` parameter is `false`, the operation of this method is identical to the overload. If `disableDaylightSavingTime` is `true`, the returned object includes no adjustment rules and a property whose value is an empty string. + + + +## Examples + The following example creates a custom time zone for the Palmer station and Anvers Island in Antarctica. It sets the `disableDaylightSavingTime` parameter in the call to the method to `true`. It then displays the new time zone's daylight saving time name, if one is present, and the number of adjustment rules to confirm that the new time zone has no daylight saving time information. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet3"::: + ]]> The parameter is . - The parameter is an empty string (""). - - -or- - + The parameter is an empty string (""). + + -or- + The parameter does not represent a whole number of minutes. The parameter is greater than 14 hours or less than -14 hours. - The adjustment rules specified in the parameter overlap. - - -or- - - The adjustment rules specified in the parameter are not in chronological order. - - -or- - - One or more elements in are . - - -or- - - A date can have multiple adjustment rules applied to it. - - -or- - + The adjustment rules specified in the parameter overlap. + + -or- + + The adjustment rules specified in the parameter are not in chronological order. + + -or- + + One or more elements in are . + + -or- + + A date can have multiple adjustment rules applied to it. + + -or- + The sum of the parameter and the value of one or more objects in the array is greater than 14 hours or less than -14 hours. How to: Create Time Zones Without Adjustment Rules How to: Create Time Zones with Adjustment Rules @@ -1531,26 +1531,26 @@ Gets the display name for the current time zone's daylight saving time. The display name for the time zone's daylight saving time. - property whose value is not or `null` does not necessarily indicate that the time zone supports daylight saving time. To determine whether the time zone supports daylight saving time, check the value of its property. - - In most cases, the `DaylightName` property of system-defined time zones is not or `null`. However, the property of custom time zones can be set to . This occurs when custom time zones are created by the or the overload and the `disableDaylightSavingTime` parameter is `true`. Therefore, your code should never assume that the value of the property is not `null` or empty. - - The property is equivalent to the property of the class. - - - -## Examples - The following example defines a method named `DisplayDateWithTimeZoneName` that uses the method to determine whether to display a time zone's standard time name or daylight saving time name. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet1"::: - + property whose value is not or `null` does not necessarily indicate that the time zone supports daylight saving time. To determine whether the time zone supports daylight saving time, check the value of its property. + + In most cases, the `DaylightName` property of system-defined time zones is not or `null`. However, the property of custom time zones can be set to . This occurs when custom time zones are created by the or the overload and the `disableDaylightSavingTime` parameter is `true`. Therefore, your code should never assume that the value of the property is not `null` or empty. + + The property is equivalent to the property of the class. + + + +## Examples + The following example defines a method named `DisplayDateWithTimeZoneName` that uses the method to determine whether to display a time zone's standard time name or daylight saving time name. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet1"::: + ]]> @@ -1599,29 +1599,29 @@ Gets the general display name that represents the time zone. The time zone's general display name. - object that represents the local time zone and outputs its display name, standard time name, and daylight saving time name. The output is displayed for a system in the U.S. Pacific Standard Time zone. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/ShowTimeZoneNames1.vb" id="Snippet2"::: - + object that represents the local time zone and outputs its display name, standard time name, and daylight saving time name. The output is displayed for a system in the U.S. Pacific Standard Time zone. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/ShowTimeZoneNames1.vb" id="Snippet2"::: + ]]> @@ -1694,28 +1694,28 @@ if is a object that is equal to the current instance; otherwise, . - object and compares it with the current instance. The test for equality is based on a comparison of values. The current instance and `obj` are considered to be equal under the following conditions: - -- The run-time type of `obj` is . - -- The two objects have the same property value. - -- The two objects have the same adjustment rules. - - If `obj` is `null`, this method returns `false`. - - - -## Examples - The following example uses the method to determine whether the local time zone is Pacific Time or Eastern Time. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/Equals/equals1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/Equals/equals1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.timezoneinfo.equals/vb/equals1.vb" id="Snippet1"::: - + object and compares it with the current instance. The test for equality is based on a comparison of values. The current instance and `obj` are considered to be equal under the following conditions: + +- The run-time type of `obj` is . + +- The two objects have the same property value. + +- The two objects have the same adjustment rules. + + If `obj` is `null`, this method returns `false`. + + + +## Examples + The following example uses the method to determine whether the local time zone is Pacific Time or Eastern Time. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/Equals/equals1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/Equals/equals1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.timezoneinfo.equals/vb/equals1.vb" id="Snippet1"::: + ]]> @@ -1786,36 +1786,36 @@ if the two objects are equal; otherwise, . - objects are considered to be equal under the following conditions: - -- The value of their property is the same. - -- They have the same adjustment rules. - - returns the Boolean value that results from evaluating the following expression: - - ```csharp - other.Id == this.Id && HasSameRules(other); - ``` - - ```vb - other.Id = me.Id AndAlso HasSameRules(other) - ``` - - If the `other` parameter is an uninitialized object, this method returns `false`. - - - -## Examples - The following example uses the method to determine whether the local time zone is Pacific Time or Eastern Time. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet7"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet7"::: - + objects are considered to be equal under the following conditions: + +- The value of their property is the same. + +- They have the same adjustment rules. + + returns the Boolean value that results from evaluating the following expression: + + ```csharp + other.Id == this.Id && HasSameRules(other); + ``` + + ```vb + other.Id = me.Id AndAlso HasSameRules(other) + ``` + + If the `other` parameter is an uninitialized object, this method returns `false`. + + + +## Examples + The following example uses the method to determine whether the local time zone is Pacific Time or Eastern Time. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet7"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet7"::: + ]]> @@ -1863,25 +1863,27 @@ The time zone identifier, which corresponds to the property. - Instantiates a new object based on its identifier. + Returns a object based on its identifier. An object whose identifier is the value of the parameter. - objects returned by the method. - - On Windows systems, `FindSystemTimeZoneById` tries to match `id` to the subkey names of the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones branch of the registry. On Linux and macOS, it uses time zone information available in the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/). If the registry or the library does not have the information for the time zone you desire, you can create a particular time zone either by calling one of the overloads of the method or by calling to deserialize a object that represents the required time zone. However, time zones created by these method calls are not system-defined time and cannot be retrieved using the method. These custom time zones can be accessed only through the object reference returned by the or method call. - -This method returns a new instance for each method call; it does not return cached objects. This may impact performance in applications that call the `FindSystemTimeZoneById` method repeatedly with the same identifier. - -## Examples - The following example uses the method to retrieve the Tokyo Standard Time zone. This object is then used to convert the local time to the time in Tokyo and to determine whether it is Tokyo Standard Time or Tokyo Daylight Time. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/convertdt2.vb" id="Snippet2"::: - + objects returned by the method. + +On Windows systems, `FindSystemTimeZoneById` tries to match `id` to the subkey names of the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones branch of the registry. On Linux and macOS, it uses time zone information available in the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/). If the registry or the library does not have the information for the time zone you desire, you can create a particular time zone either by calling one of the overloads of the method or by calling to deserialize a object that represents the required time zone. However, time zones created by these method calls are not system-defined time and cannot be retrieved using the method. These custom time zones can be accessed only through the object reference returned by the or method call. + +In .NET 7 and earlier versions, this method returns a new instance for each method call. This might impact performance in applications that call the `FindSystemTimeZoneById` method repeatedly with the same identifier. (In .NET 8 and later versions, this method always returns a cached instance.) + +## Examples + +The following example uses the method to retrieve the Tokyo Standard Time zone. This object is then used to convert the local time to the time in Tokyo and to determine whether it is Tokyo Standard Time or Tokyo Daylight Time. + +:::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.cs" id="Snippet2"::: +:::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.fs" id="Snippet2"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/convertdt2.vb" id="Snippet2"::: + ]]> The system does not have enough memory to hold information about the time zone. @@ -1890,7 +1892,7 @@ This method returns a new instance for each method ca The process does not have the permissions required to read from the registry key that contains the time zone information. The time zone identifier was found, but the registry data is corrupted. - How to: Instantiate a TimeZoneInfo Object + How to: Obtain a TimeZoneInfo Object @@ -1937,20 +1939,20 @@ This method returns a new instance for each method ca Deserializes a string to re-create an original serialized object. The original serialized object. - method in a standalone executable or use an application's setup program to save the time zone as a string. The application can then retrieve this string from its storage location and instantiate it using the method. - - - -## Examples - The following example tries to retrieve the Antarctica/South Pole time zone from the local system. If it fails, the code tries to retrieve information about the time zone from a text file in the application directory. If this attempt fails, the code creates the time zone and writes information about the time zone to the text file. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet4"::: - + method in a standalone executable or use an application's setup program to save the time zone as a string. The application can then retrieve this string from its storage location and instantiate it using the method. + + + +## Examples + The following example tries to retrieve the Antarctica/South Pole time zone from the local system. If it fails, the code tries to retrieve information about the time zone from a text file in the application directory. If this attempt fails, the code creates the time zone and writes information about the time zone to the text file. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet4"::: + ]]> The parameter is . @@ -2001,26 +2003,26 @@ This method returns a new instance for each method ca Retrieves an array of objects that apply to the current object. An array of objects for this time zone. - method retrieves an array of objects. Each object in the array defines the effective start and end date of that time zone adjustment, as well as its delta (the exact amount by which the adjustment causes the time to change). In addition, two properties return objects that define when each annual transition to and from standard time occurs. - - If a time zone has multiple adjustment rules, they are generally ordered from earliest (at index 0) to latest (at index - 1). - - If a time zone has no adjustment rules, the method returns an empty array (an array whose is zero). - - Any modifications to the elements of the array returned by the method are not reflected in the adjustment rules that belong to a particular time zone. To modify a time zone's adjustment rules (such as to reflect its historical transition to and from daylight saving time) you must create a new time zone with the appropriate adjustment rules, rather than modify the existing one. - - - -## Examples - The following example retrieves all time zones that are defined on the local system and displays complete information about their adjustment rules to the console. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.AdjustmentRule.Class/vb/System.TimeZone2.AdjustmentRule.Class.vb" id="Snippet3"::: - + method retrieves an array of objects. Each object in the array defines the effective start and end date of that time zone adjustment, as well as its delta (the exact amount by which the adjustment causes the time to change). In addition, two properties return objects that define when each annual transition to and from standard time occurs. + + If a time zone has multiple adjustment rules, they are generally ordered from earliest (at index 0) to latest (at index - 1). + + If a time zone has no adjustment rules, the method returns an empty array (an array whose is zero). + + Any modifications to the elements of the array returned by the method are not reflected in the adjustment rules that belong to a particular time zone. To modify a time zone's adjustment rules (such as to reflect its historical transition to and from daylight saving time) you must create a new time zone with the appropriate adjustment rules, rather than modify the existing one. + + + +## Examples + The following example retrieves all time zones that are defined on the local system and displays complete information about their adjustment rules to the console. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.AdjustmentRule.Class/vb/System.TimeZone2.AdjustmentRule.Class.vb" id="Snippet3"::: + ]]> The system does not have enough memory to make an in-memory copy of the adjustment rules. @@ -2088,36 +2090,36 @@ This method returns a new instance for each method ca Returns information about the possible dates and times that an ambiguous date and time can be mapped to. An array of objects that represents possible Coordinated Universal Time (UTC) offsets that a particular date and time can be mapped to. - property and the object, as the following table shows. - -|TimeZoneInfo object type|Kind property value|Behavior| -|------------------------------|-------------------------|--------------| -|| or |Returns ambiguous time offsets for `dateTime`.| -|||Converts `dateTime` to the local time, and then returns ambiguous time offsets for that time.| -||Any value.|Throws an .| -|Any other time zone.| or |Converts `dateTime` to the specified time zone, and then determines whether that time is ambiguous.| -|Any other time zone.||Determines whether `dateTime` is ambiguous in the specified time zone.| - - The order of objects in the array returned by this method is undefined. However, you can determine which element represents an offset from the time zone's standard time by comparing its value with the time zone's property. To map an ambiguous time to a time zone's standard time, see [How to: Resolve Ambiguous Times](/dotnet/standard/datetime/resolve-ambiguous-times). - - - -## Examples - The following example defines a method named `ShowPossibleUtcTimes` that uses the method to map an ambiguous time to its possible corresponding Coordinated Universal Time (UTC) times. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.GetAmbiguousTimeOffsets/vb/System.TimeZone2.GetAmbiguousTimeOffsets.vb" id="Snippet1"::: - - The method can then be called using code such as the following: - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.GetAmbiguousTimeOffsets/vb/System.TimeZone2.GetAmbiguousTimeOffsets.vb" id="Snippet2"::: - + property and the object, as the following table shows. + +|TimeZoneInfo object type|Kind property value|Behavior| +|------------------------------|-------------------------|--------------| +|| or |Returns ambiguous time offsets for `dateTime`.| +|||Converts `dateTime` to the local time, and then returns ambiguous time offsets for that time.| +||Any value.|Throws an .| +|Any other time zone.| or |Converts `dateTime` to the specified time zone, and then determines whether that time is ambiguous.| +|Any other time zone.||Determines whether `dateTime` is ambiguous in the specified time zone.| + + The order of objects in the array returned by this method is undefined. However, you can determine which element represents an offset from the time zone's standard time by comparing its value with the time zone's property. To map an ambiguous time to a time zone's standard time, see [How to: Resolve Ambiguous Times](/dotnet/standard/datetime/resolve-ambiguous-times). + + + +## Examples + The following example defines a method named `ShowPossibleUtcTimes` that uses the method to map an ambiguous time to its possible corresponding Coordinated Universal Time (UTC) times. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.GetAmbiguousTimeOffsets/vb/System.TimeZone2.GetAmbiguousTimeOffsets.vb" id="Snippet1"::: + + The method can then be called using code such as the following: + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.GetAmbiguousTimeOffsets/vb/System.TimeZone2.GetAmbiguousTimeOffsets.vb" id="Snippet2"::: + ]]> @@ -2175,13 +2177,13 @@ This method returns a new instance for each method ca Returns information about the possible dates and times that an ambiguous date and time can be mapped to. An array of objects that represents possible Coordinated Universal Time (UTC) offsets that a particular date and time can be mapped to. - property of the `dateTimeOffset` parameter and the object. If the value of the property corresponds to the current time zone's possible offsets from Coordinated Universal Time (UTC) for that date and time, the method returns the possible offsets. Otherwise, it converts `dateTimeOffset` to the time in the current time zone, and then returns the possible offsets of that date and time. - - The order of objects in the array returned by this method is undefined. However, you can determine which element represents an offset from the time zone's standard time by comparing its value with the time zone's property. To map an ambiguous time to a time zone's standard time, see [How to: Resolve Ambiguous Times](/dotnet/standard/datetime/resolve-ambiguous-times). - + property of the `dateTimeOffset` parameter and the object. If the value of the property corresponds to the current time zone's possible offsets from Coordinated Universal Time (UTC) for that date and time, the method returns the possible offsets. Otherwise, it converts `dateTimeOffset` to the time in the current time zone, and then returns the possible offsets of that date and time. + + The order of objects in the array returned by this method is undefined. However, you can determine which element represents an offset from the time zone's standard time by comparing its value with the time zone's property. To map an ambiguous time to a time zone's standard time, see [How to: Resolve Ambiguous Times](/dotnet/standard/datetime/resolve-ambiguous-times). + ]]> @@ -2236,11 +2238,11 @@ This method returns a new instance for each method ca Serves as a hash function for hashing algorithms and data structures such as hash tables. A 32-bit signed integer that serves as the hash code for this object. - method, see . - + method, see . + ]]> @@ -2302,32 +2304,32 @@ This method returns a new instance for each method ca Returns a sorted collection of all the time zones about which information is available on the local system. A read-only collection of objects. - method retrieves all available time zone information from the subkeys of the registry's HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones key on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. If it is unable to successfully retrieve and parse values for particular string properties of individual objects, this method sets their value to an empty string (""). - -> [!IMPORTANT] -> The method returns a collection of objects only for time zones defined in the Windows registry or the ICU library. It does not include time zones created using the overloads of the method. These are accessible only through the object reference returned by the time zone creation method. - - The collection returned by this method is sorted by UTC offset and, for time zones that have the same UTC offset, by the display name using the current culture. For information about the display name, see . - - The object returned by this method supports the interface, which means that it can be iterated using the `foreach` (in C#) or `For Each…Next` (in Visual Basic) statements. Each iteration of the loop provides the next object in the collection. - - The collection of objects represents time zones defined on the local computer; it does not necessarily provide complete information for all time zones during all time periods. If your application requires time zones not found on the local computer, you can create custom time zones using the overloads of the method. For more information, see [How to: Create Time Zones Without Adjustment Rules](/dotnet/standard/datetime/create-time-zones-without-adjustment-rules) and [How to: Create Time Zones with Adjustment Rules](/dotnet/standard/datetime/create-time-zones-with-adjustment-rules). - - You can also determine whether an individual time zone is defined on the local computer by calling the method and providing the identifier of the time zone you want to retrieve as a parameter. - - - -## Examples - The following example retrieves a collection of time zone objects that represent the time zones defined on a computer and writes information about them to a text file. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/getsystemtimezones1.cs" id="Snippet6"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/getsystemtimezones1.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/getsystemtimezones1.vb" id="Snippet6"::: - :::code language="powershell" source="~/snippets/powershell/VS_Snippets_CLR_System/System.TimeZone2.Class/PS/Timezone2_Examples.ps1"::: - + method retrieves all available time zone information from the subkeys of the registry's HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones key on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. If it is unable to successfully retrieve and parse values for particular string properties of individual objects, this method sets their value to an empty string (""). + +> [!IMPORTANT] +> The method returns a collection of objects only for time zones defined in the Windows registry or the ICU library. It does not include time zones created using the overloads of the method. These are accessible only through the object reference returned by the time zone creation method. + + The collection returned by this method is sorted by UTC offset and, for time zones that have the same UTC offset, by the display name using the current culture. For information about the display name, see . + + The object returned by this method supports the interface, which means that it can be iterated using the `foreach` (in C#) or `For Each…Next` (in Visual Basic) statements. Each iteration of the loop provides the next object in the collection. + + The collection of objects represents time zones defined on the local computer; it does not necessarily provide complete information for all time zones during all time periods. If your application requires time zones not found on the local computer, you can create custom time zones using the overloads of the method. For more information, see [How to: Create Time Zones Without Adjustment Rules](/dotnet/standard/datetime/create-time-zones-without-adjustment-rules) and [How to: Create Time Zones with Adjustment Rules](/dotnet/standard/datetime/create-time-zones-with-adjustment-rules). + + You can also determine whether an individual time zone is defined on the local computer by calling the method and providing the identifier of the time zone you want to retrieve as a parameter. + + + +## Examples + The following example retrieves a collection of time zone objects that represent the time zones defined on a computer and writes information about them to a text file. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/getsystemtimezones1.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/getsystemtimezones1.fs" id="Snippet6"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/getsystemtimezones1.vb" id="Snippet6"::: + :::code language="powershell" source="~/snippets/powershell/VS_Snippets_CLR_System/System.TimeZone2.Class/PS/Timezone2_Examples.ps1"::: + ]]> There is insufficient memory to store all time zone information. @@ -2364,10 +2366,10 @@ This method returns a new instance for each method ca If , The collection returned may not necessarily be sorted. - Returns a containing all valid TimeZone's from the local machine. + Returns a containing all valid TimeZone's from the local machine. This method does *not* throw TimeZoneNotFoundException or InvalidTimeZoneException. To be added. - By setting the skipSorting parameter to , the method will attempt to avoid sorting the returned collection. + By setting the skipSorting parameter to , the method will attempt to avoid sorting the returned collection. This option can be beneficial when the caller does not require a sorted list and aims to enhance the performance. @@ -2432,24 +2434,24 @@ This method returns a new instance for each method ca Calculates the offset or difference between the time in this time zone and Coordinated Universal Time (UTC) for a particular date and time. An object that indicates the time difference between the two time zones. - property, which returns the difference between Coordinated Universal Time (UTC) and the time zone's standard time and, therefore, does not take adjustment rules into account. - - If the `dateTime` parameter's property does not correspond to the time zone object, this method performs the necessary conversion before returning a result. For example, this can occur if the property is but the time zone object is not the local time zone. If `dateTime` is ambiguous, or if the converted time is ambiguous, this method interprets the ambiguous time as a standard time. If `dateTime` is invalid, this method returns a object that reflects the difference between UTC and the time zone's standard time. - - The method is similar in operation to the method of the class. - - - -## Examples - The following example illustrates the use of the method with different time zones and with date values that have different property values. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/GetUtcOffset/System.TimeZone2.GetUtcOffset.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/GetUtcOffset/System.TimeZone2.GetUtcOffset.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.GetUtcOffset/vb/System.TimeZone2.GetUtcOffset.vb" id="Snippet1"::: - + property, which returns the difference between Coordinated Universal Time (UTC) and the time zone's standard time and, therefore, does not take adjustment rules into account. + + If the `dateTime` parameter's property does not correspond to the time zone object, this method performs the necessary conversion before returning a result. For example, this can occur if the property is but the time zone object is not the local time zone. If `dateTime` is ambiguous, or if the converted time is ambiguous, this method interprets the ambiguous time as a standard time. If `dateTime` is invalid, this method returns a object that reflects the difference between UTC and the time zone's standard time. + + The method is similar in operation to the method of the class. + + + +## Examples + The following example illustrates the use of the method with different time zones and with date values that have different property values. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/GetUtcOffset/System.TimeZone2.GetUtcOffset.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/GetUtcOffset/System.TimeZone2.GetUtcOffset.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.GetUtcOffset/vb/System.TimeZone2.GetUtcOffset.vb" id="Snippet1"::: + ]]> @@ -2503,11 +2505,11 @@ This method returns a new instance for each method ca Calculates the offset or difference between the time in this time zone and Coordinated Universal Time (UTC) for a particular date and time. An object that indicates the time difference between Coordinated Universal Time (UTC) and the current time zone. - property, which returns the difference between Coordinated Universal Time (UTC) and the time zone's standard time and, therefore, does not take adjustment rules into account. - + property, which returns the difference between Coordinated Universal Time (UTC) and the time zone's standard time and, therefore, does not take adjustment rules into account. + ]]> @@ -2590,20 +2592,20 @@ This method returns a new instance for each method ca if the two time zones have identical adjustment rules and an identical base offset; otherwise, . - method, the method indicates whether two time zones have the same base offset (as defined by the property) and the same adjustment rules. Unlike the method, does not compare time zone identifiers (as defined by the property). - - - -## Examples - Typically, a number of time zones defined in the registry on Windows and the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS have the same offset from Coordinated Universal Time (UTC) and the same adjustment rules. The following example displays a list of these time zones to the console. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/HasSameRules/HasSameRules.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/HasSameRules/HasSameRules.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.HasSameRules/vb/HasSameRules.vb" id="Snippet1"::: - + method, the method indicates whether two time zones have the same base offset (as defined by the property) and the same adjustment rules. Unlike the method, does not compare time zone identifiers (as defined by the property). + + + +## Examples + Typically, a number of time zones defined in the registry on Windows and the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS have the same offset from Coordinated Universal Time (UTC) and the same adjustment rules. The following example displays a list of these time zones to the console. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/HasSameRules/HasSameRules.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/HasSameRules/HasSameRules.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.HasSameRules/vb/HasSameRules.vb" id="Snippet1"::: + ]]> The parameter is . @@ -2651,25 +2653,25 @@ This method returns a new instance for each method ca Gets the time zone identifier. The time zone identifier. - method to instantiate a object that represents a particular time zone. - -> [!IMPORTANT] -> Although a key name in the Windows registry can be a maximum of 255 characters, we recommend that an identifier that you assign to a custom time zone be 32 characters or fewer. The longer the identifier, the greater the probability that an incorrect key name will be supplied when retrieving it. - - The value of the property is usually, but not always, identical to that of the property. The identifier of the Coordinated Universal Time zone is UTC. - - - -## Examples - The following example lists the identifier of each of the time zones defined on the local computer. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet5"::: - + method to instantiate a object that represents a particular time zone. + +> [!IMPORTANT] +> Although a key name in the Windows registry can be a maximum of 255 characters, we recommend that an identifier that you assign to a custom time zone be 32 characters or fewer. The longer the identifier, the greater the probability that an incorrect key name will be supplied when retrieving it. + + The value of the property is usually, but not always, identical to that of the property. The identifier of the Coordinated Universal Time zone is UTC. + + + +## Examples + The following example lists the identifier of each of the time zones defined on the local computer. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet5"::: + ]]> @@ -2736,33 +2738,33 @@ This method returns a new instance for each method ca if the parameter is ambiguous; otherwise, . - 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 property and the object, as the following table shows. - -|TimeZoneInfo object type|Kind property value|Behavior| -|------------------------------|-------------------------|--------------| -|| or |Determines whether the `dateTime` parameter is ambiguous.| -|||Converts `dateTime` to the local time and then determines whether that time is ambiguous.| -|| or |Returns `false`.| -|||If `dateTime` is ambiguous, assumes it is a standard time, converts it to UTC, and returns `false`.| -|Any other time zone.| or |Converts `dateTime` to the time in the specified time zone and then determines whether that time is ambiguous.| -|Any other time zone.||Determines whether `dateTime` is ambiguous.| - - - -## Examples - 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 method of a 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. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet8"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet8"::: - + 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 property and the object, as the following table shows. + +|TimeZoneInfo object type|Kind property value|Behavior| +|------------------------------|-------------------------|--------------| +|| or |Determines whether the `dateTime` parameter is ambiguous.| +|||Converts `dateTime` to the local time and then determines whether that time is ambiguous.| +|| or |Returns `false`.| +|||If `dateTime` is ambiguous, assumes it is a standard time, converts it to UTC, and returns `false`.| +|Any other time zone.| or |Converts `dateTime` to the time in the specified time zone and then determines whether that time is ambiguous.| +|Any other time zone.||Determines whether `dateTime` is ambiguous.| + + + +## Examples + 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 method of a 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. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet8"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet8"::: + ]]> The property of the value is and is an invalid time. @@ -2818,13 +2820,13 @@ This method returns a new instance for each method ca if the parameter is ambiguous in the current time zone; otherwise, . - property of the `dateTimeOffset` parameter and the current time zone. If the value of the 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. - + property of the `dateTimeOffset` parameter and the current time zone. If the value of the 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. + ]]> @@ -2891,44 +2893,44 @@ This method returns a new instance for each method ca if the parameter is a daylight saving time; otherwise, . - is affected by the relationship between the time zone represented by the object and the property of the `dateTime` parameter, as the following table shows. - -|TimeZoneInfo object|DateTime.Kind property|Result| -|-------------------------|----------------------------|------------| -||`DateTimeKind.Local`|Determines whether `dateTime` is daylight saving time.| -||`DateTimeKind.Utc`|Converts `dateTime` from Coordinated Universal Time (UTC) to local time and determines whether it is daylight saving time.| -||`DateTimeKind.Unspecified`|Assumes that `dateTime` represents local time and determines whether it is daylight saving time.| -||`DateTimeKind.Local`, `DateTimeKind.Unspecified`, or `DateTimeKind.Utc`|Returns `false` (UTC does not support daylight saving time).| -|Any other object.|`DateTimeKind.Local`|Converts the local time to the equivalent time of the object and then determines whether the latter is daylight saving time.| -|Any other object.|`DateTimeKind.Utc`|Converts UTC to the equivalent time of the object and then determines whether the latter is daylight saving time.| -|Any other object.|`DateTimeKind.Unspecified`|Determines whether `dateTime` is daylight saving time.| - - If the time zone represented by the object does not support daylight saving time, the method always returns `false`. A number of time zones, including , do not observe daylight saving time. To determine whether a time zone supports daylight saving time, retrieve the value of its property. - - If the `dateTime` parameter specifies an ambiguous time in the current object's time zone, the method interprets `dateTime` as standard time and returns `false` if its property is or . If the property is , this method will select the correct ambiguous time and indicate whether it is a daylight saving time. - - Because the method can return `false` for a date and time that is ambiguous (that is, a date and time that can represent either a standard time or a daylight saving time in a particular time zone), the method can be paired with the method to determine whether a time may be a daylight saving time. Because an ambiguous time is one that can be both a daylight saving time and a standard time, the method can be called first to determine whether a date and time may be a daylight saving time. If the method returns `false`, the method can be called to determine whether the value is a daylight saving time. The following example illustrates this technique. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet2"::: - - If the `dateTime` parameter specifies an invalid time, the method call throws an if the value of the `dateTime` parameter's property is ; otherwise, the method returns `false`. - - Call the method to determine whether to use a time zone's value or its value when displaying the time zone name. See the Example section for an illustration. - - - -## Examples - The following example defines a method named `DisplayDateWithTimeZoneName` that uses the method to determine whether to display a time zone's standard time name or daylight saving time name. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet1"::: - + is affected by the relationship between the time zone represented by the object and the property of the `dateTime` parameter, as the following table shows. + +|TimeZoneInfo object|DateTime.Kind property|Result| +|-------------------------|----------------------------|------------| +||`DateTimeKind.Local`|Determines whether `dateTime` is daylight saving time.| +||`DateTimeKind.Utc`|Converts `dateTime` from Coordinated Universal Time (UTC) to local time and determines whether it is daylight saving time.| +||`DateTimeKind.Unspecified`|Assumes that `dateTime` represents local time and determines whether it is daylight saving time.| +||`DateTimeKind.Local`, `DateTimeKind.Unspecified`, or `DateTimeKind.Utc`|Returns `false` (UTC does not support daylight saving time).| +|Any other object.|`DateTimeKind.Local`|Converts the local time to the equivalent time of the object and then determines whether the latter is daylight saving time.| +|Any other object.|`DateTimeKind.Utc`|Converts UTC to the equivalent time of the object and then determines whether the latter is daylight saving time.| +|Any other object.|`DateTimeKind.Unspecified`|Determines whether `dateTime` is daylight saving time.| + + If the time zone represented by the object does not support daylight saving time, the method always returns `false`. A number of time zones, including , do not observe daylight saving time. To determine whether a time zone supports daylight saving time, retrieve the value of its property. + + If the `dateTime` parameter specifies an ambiguous time in the current object's time zone, the method interprets `dateTime` as standard time and returns `false` if its property is or . If the property is , this method will select the correct ambiguous time and indicate whether it is a daylight saving time. + + Because the method can return `false` for a date and time that is ambiguous (that is, a date and time that can represent either a standard time or a daylight saving time in a particular time zone), the method can be paired with the method to determine whether a time may be a daylight saving time. Because an ambiguous time is one that can be both a daylight saving time and a standard time, the method can be called first to determine whether a date and time may be a daylight saving time. If the method returns `false`, the method can be called to determine whether the value is a daylight saving time. The following example illustrates this technique. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet2"::: + + If the `dateTime` parameter specifies an invalid time, the method call throws an if the value of the `dateTime` parameter's property is ; otherwise, the method returns `false`. + + Call the method to determine whether to use a time zone's value or its value when displaying the time zone name. See the Example section for an illustration. + + + +## Examples + The following example defines a method named `DisplayDateWithTimeZoneName` that uses the method to determine whether to display a time zone's standard time name or daylight saving time name. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet1"::: + ]]> The property of the value is and is an invalid time. @@ -2984,13 +2986,13 @@ This method returns a new instance for each method ca if the parameter is a daylight saving time; otherwise, . - is affected by the relationship between the time zone represented by the object and the property of the `dateTimeOffset` parameter. If `dateTimeOffset` does not correspond to the current time zone's offset from Coordinated Universal Time (UTC), the method converts that time to the time in the current time zone. It then determines whether that date and time is a daylight saving time. - - If the time zone represented by the object does not support daylight saving time, the method always returns `false`. To determine whether a time zone supports daylight saving time, retrieve the value of its property. - + is affected by the relationship between the time zone represented by the object and the property of the `dateTimeOffset` parameter. If `dateTimeOffset` does not correspond to the current time zone's offset from Coordinated Universal Time (UTC), the method converts that time to the time in the current time zone. It then determines whether that date and time is a daylight saving time. + + If the time zone represented by the object does not support daylight saving time, the method always returns `false`. To determine whether a time zone supports daylight saving time, retrieve the value of its property. + ]]> @@ -3045,29 +3047,29 @@ This method returns a new instance for each method ca if is invalid; otherwise, . - property of the `dateTime` parameter affects whether `dateTime` represents an invalid time, as the following table shows. - -|DateTime.Kind property|TimeZoneInfo object (if applicable)|Behavior| -|----------------------------|-------------------------------------------|--------------| -|||Determines whether the time is invalid.| -|| or a non-local time zone.|Converts `dateTime` to the time of the object and returns `false`.| -||Not applicable.|Assumes `dateTime` is the time of the object and determines whether it is invalid.| -||Not applicable.|Returns `false`.| - - - -## Examples - In the Pacific Time zone, daylight saving time begins at 2:00 A.M. on April 2, 2006. The following code passes the time at one-minute intervals from 1:59 A.M. on April 2, 2006, to 3:01 A.M. on April 2, 2006, to the method of a object that represents the Pacific Time zone. The console output indicates that all times from 2:00 A.M. on April 2, 2006, to 2:59 A.M. on April 2, 2006, are invalid. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet9"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet9"::: - + property of the `dateTime` parameter affects whether `dateTime` represents an invalid time, as the following table shows. + +|DateTime.Kind property|TimeZoneInfo object (if applicable)|Behavior| +|----------------------------|-------------------------------------------|--------------| +|||Determines whether the time is invalid.| +|| or a non-local time zone.|Converts `dateTime` to the time of the object and returns `false`.| +||Not applicable.|Assumes `dateTime` is the time of the object and determines whether it is invalid.| +||Not applicable.|Returns `false`.| + + + +## Examples + In the Pacific Time zone, daylight saving time begins at 2:00 A.M. on April 2, 2006. The following code passes the time at one-minute intervals from 1:59 A.M. on April 2, 2006, to 3:01 A.M. on April 2, 2006, to the method of a object that represents the Pacific Time zone. The console output indicates that all times from 2:00 A.M. on April 2, 2006, to 2:59 A.M. on April 2, 2006, are invalid. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet9"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet9"::: + ]]> @@ -3123,37 +3125,37 @@ This method returns a new instance for each method ca Gets a object that represents the local time zone. An object that represents the local time zone. - [!IMPORTANT] -> You should always access the local time zone through the property rather than assigning the local time zone to a object variable. This prevents the object variable from being invalidated by a call to the method. - - On Windows systems, the object returned by the property reflects the setting of the **Automatically adjust clock for Daylight Saving Time** checkbox in the Control Panel **Date and Time** application. If the checkbox is unchecked, the cached copy of the local time zone contains no daylight saving time information. This means that: - -- The local time zone's method returns an array whose length is zero. - -- The local time zone's property returns `false`. - -- The local time zone has no ambiguous or invalid times (all calls to or return `false`). - -- All calls to with individual local times return false. - - This is not true, however, if a reference to the local time zone is retrieved using the method. - - The property corresponds to the property of the class. - - - -## Examples - The following example retrieves a object that represents the local time zone and outputs its display name, standard time name, and daylight saving time name. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/ShowTimeZoneNames1.vb" id="Snippet2"::: - + [!IMPORTANT] +> You should always access the local time zone through the property rather than assigning the local time zone to a object variable. This prevents the object variable from being invalidated by a call to the method. + + On Windows systems, the object returned by the property reflects the setting of the **Automatically adjust clock for Daylight Saving Time** checkbox in the Control Panel **Date and Time** application. If the checkbox is unchecked, the cached copy of the local time zone contains no daylight saving time information. This means that: + +- The local time zone's method returns an array whose length is zero. + +- The local time zone's property returns `false`. + +- The local time zone has no ambiguous or invalid times (all calls to or return `false`). + +- All calls to with individual local times return false. + + This is not true, however, if a reference to the local time zone is retrieved using the method. + + The property corresponds to the property of the class. + + + +## Examples + The following example retrieves a object that represents the local time zone and outputs its display name, standard time name, and daylight saving time name. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/ShowTimeZoneNames1.vb" id="Snippet2"::: + ]]> How to: Access the Predefined UTC and Local Time Zone Objects @@ -3203,24 +3205,24 @@ This method returns a new instance for each method ca Gets the display name for the time zone's standard time. The display name of the time zone's standard time. - property is identical to the property of the class. - - If the operating system language is English, the value of the property is usually, but not always, identical to that of the property. - - - -## Examples - The following example defines a method named `DisplayDateWithTimeZoneName` that uses the method to determine whether to display a time zone's standard time name or daylight saving time name. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet1"::: - + property is identical to the property of the class. + + If the operating system language is English, the value of the property is usually, but not always, identical to that of the property. + + + +## Examples + The following example defines a method named `DisplayDateWithTimeZoneName` that uses the method to determine whether to display a time zone's standard time name or daylight saving time name. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet1"::: + ]]> @@ -3270,20 +3272,20 @@ This method returns a new instance for each method ca if the time zone supports daylight saving time; otherwise, . - property for the local time zone returned by the property reflects the setting of the Control Panel **Date and Time** application's checkbox that defines whether the system automatically adjusts for daylight saving time. If it is unchecked, or if no checkbox is displayed for a time zone, the value of this property is `false`. - - - -## Examples - The following example retrieves a collection of all time zones that are available on a local system and displays the names of those that do not support daylight saving time. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet4"::: - + property for the local time zone returned by the property reflects the setting of the Control Panel **Date and Time** application's checkbox that defines whether the system automatically adjusts for daylight saving time. If it is unchecked, or if no checkbox is displayed for a time zone, the value of this property is `false`. + + + +## Examples + The following example retrieves a collection of all time zones that are available on a local system and displays the names of those that do not support daylight saving time. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet4"::: + ]]> @@ -3435,28 +3437,28 @@ This method returns a new instance for each method ca Converts the current object to a serialized string. A string that represents the current object. - method to instantiate the necessary time zones as objects. The application can then call the method to convert the time zone object to a string. - - The object should also be stored in a location where the application can retrieve it when needed. Possible locations include: - -- The registry on Windows systems. - -- An application resource file. - -- An external file, such as a text file. - - - -## Examples - The following example tries to retrieve the Antarctica/South Pole time zone from the local system. If it fails, the code tries to retrieve information about the time zone from a text file in the application directory. If this attempt fails, the code creates the time zone and writes information about it to the text file. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet4"::: - + method to instantiate the necessary time zones as objects. The application can then call the method to convert the time zone object to a string. + + The object should also be stored in a location where the application can retrieve it when needed. Possible locations include: + +- The registry on Windows systems. + +- An application resource file. + +- An external file, such as a text file. + + + +## Examples + The following example tries to retrieve the Antarctica/South Pole time zone from the local system. If it fails, the code tries to retrieve information about the time zone from a text file in the application directory. If this attempt fails, the code creates the time zone and writes information about it to the text file. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet4"::: + ]]> @@ -3508,11 +3510,11 @@ This method returns a new instance for each method ca Returns the current object's display name. The value of the property of the current object. - objects to a list control such as the control, the control automatically calls the method to extract a string that describes each object to be represented in the list. As a result, you do not need to store a meaningful description of the object as a string, and the user does not need to use that string to extract the object from the collection. See [How to: Enumerate Time Zones Present on a Computer](/dotnet/standard/datetime/enumerate-time-zones) for more detail. - + objects to a list control such as the control, the control automatically calls the method to extract a string that describes each object to be represented in the list. As a result, you do not need to store a meaningful description of the object as a string, and the user does not need to use that string to extract the object from the collection. See [How to: Enumerate Time Zones Present on a Computer](/dotnet/standard/datetime/enumerate-time-zones) for more detail. + ]]> @@ -3566,18 +3568,18 @@ This method returns a new instance for each method ca if the ID conversion succeeded, otherwise. - @@ -3631,18 +3633,18 @@ If the application is running on a Windows OS version that lacks the ICU library if the ID conversion succeeded, otherwise. - @@ -3707,18 +3709,18 @@ If the application is running on a Windows OS version that lacks the ICU library if the ID conversion succeeded, otherwise. - @@ -3816,25 +3818,25 @@ If the application is running on a Windows OS version that lacks the ICU library Gets a object that represents the Coordinated Universal Time (UTC) zone. An object that represents the Coordinated Universal Time (UTC) zone. - object is not retrieved from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. - -> [!IMPORTANT] -> You should always access the Coordinated Universal Time (UTC) zone through the property rather than assigning the UTC time zone to a object variable. This prevents the object variable from being invalidated by a call to the method. - - Coordinated Universal Time was previously known as Greenwich Mean Time (GMT). - - - -## Examples - The following example retrieves a object that represents Coordinated Universal Time (UTC) and outputs its display name, standard time name, and daylight saving time name. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet3"::: - + object is not retrieved from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. + +> [!IMPORTANT] +> You should always access the Coordinated Universal Time (UTC) zone through the property rather than assigning the UTC time zone to a object variable. This prevents the object variable from being invalidated by a call to the method. + + Coordinated Universal Time was previously known as Greenwich Mean Time (GMT). + + + +## Examples + The following example retrieves a object that represents Coordinated Universal Time (UTC) and outputs its display name, standard time name, and daylight saving time name. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet3"::: + ]]> How to: Access the Predefined UTC and Local Time Zone Objects