TimeZoneInfo.CreateCustomTimeZone Método
Definição
Define um fuso horário que não foi encontrado no computador local.Defines a time zone that is not found on the local computer.
Sobrecargas
| CreateCustomTimeZone(String, TimeSpan, String, String) |
Cria um fuso horário personalizado com um identificador especificado, um desvio de UTC (Tempo Universal Coordenado), um nome de exibição e um nome de exibição do horário padrão.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. |
| CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[]) |
Cria um fuso horário personalizado com um identificador especificado, um deslocamento do UTC (Tempo Universal Coordenado), um nome de exibição, um nome de hora padrão e um nome e regras do horário de verão.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. |
| CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[], Boolean) |
Cria um fuso horário personalizado com um identificador especificado, um deslocamento do UTC (Tempo Universal Coordenado), um nome de exibição, um nome de hora padrão, um nome de horário de verão, regras de horário de verão e um valor que indica se o objeto retornado reflete as informações sobre horário de verão.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. |
CreateCustomTimeZone(String, TimeSpan, String, String)
Cria um fuso horário personalizado com um identificador especificado, um desvio de UTC (Tempo Universal Coordenado), um nome de exibição e um nome de exibição do horário padrão.Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, and a standard time display name.
public:
static TimeZoneInfo ^ CreateCustomTimeZone(System::String ^ id, TimeSpan baseUtcOffset, System::String ^ displayName, System::String ^ standardDisplayName);
public static TimeZoneInfo CreateCustomTimeZone (string id, TimeSpan baseUtcOffset, string? displayName, string? standardDisplayName);
public static TimeZoneInfo CreateCustomTimeZone (string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName);
static member CreateCustomTimeZone : string * TimeSpan * string * string -> TimeZoneInfo
Public Shared Function CreateCustomTimeZone (id As String, baseUtcOffset As TimeSpan, displayName As String, standardDisplayName As String) As TimeZoneInfo
Parâmetros
- id
- String
O identificador do fuso horário.The time zone's identifier.
- baseUtcOffset
- TimeSpan
Um objeto que representa a diferença de horas entre esse fuso horário e o UTC (Horário Universal Coordenado).An object that represents the time difference between this time zone and Coordinated Universal Time (UTC).
- displayName
- String
O nome de exibição do novo fuso horário.The display name of the new time zone.
- standardDisplayName
- String
O nome do horário padrão do novo fuso horário.The name of the new time zone's standard time.
Retornos
O novo fuso horário.The new time zone.
Exceções
O parâmetro id é null.The id parameter is null.
O parâmetro id é uma cadeia de caracteres vazia ("").The id parameter is an empty string ("").
- ou --or-
O parâmetro baseUtcOffset não representa um número inteiro de minutos.The baseUtcOffset parameter does not represent a whole number of minutes.
O parâmetro baseUtcOffset é maior que 14 horas ou menor que -14 horas.The baseUtcOffset parameter is greater than 14 hours or less than -14 hours.
Exemplos
O exemplo a seguir cria um fuso horário personalizado para as regiões de compartimento Mawson e Holme da Antártica.The following example creates a custom time zone for the Mawson and Holme Bay regions of Antarctica. Em seguida, ele exibe o resultado da conversão da hora local para a hora no novo fuso horário.It then displays the result of converting the local time to the time in the new time zone.
string displayName = "(GMT+06:00) Antarctica/Mawson Time";
string standardName = "Mawson Time";
TimeSpan offset = new TimeSpan(06, 00, 00);
TimeZoneInfo mawson = TimeZoneInfo.CreateCustomTimeZone(standardName, offset, displayName, standardName);
Console.WriteLine("The current time is {0} {1}",
TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, mawson),
mawson.StandardName);
Dim displayName As String = "(GMT+06:00) Antarctica/Mawson Time"
Dim standardName As String = "Mawson Time"
Dim offset As TimeSpan = New TimeSpan(06, 00, 00)
Dim mawson As TimeZoneInfo = TimeZoneInfo.CreateCustomTimeZone(standardName, offset, displayName, standardName)
Console.WriteLine("The current time is {0} {1}", _
TimeZoneInfo.ConvertTime(Date.Now, TimeZoneInfo.Local, mawson), _
mawson.StandardName)
Comentários
Essa sobrecarga do CreateCustomTimeZone(String, TimeSpan, String, String) método é adequada para criar um fuso horário que não tem ajustes (ou seja, um fuso horário que não dá suporte ao horário de verão).This overload of the CreateCustomTimeZone(String, TimeSpan, String, String) method is suitable for creating a time zone that has no adjustments (that is, a time zone that does not support daylight saving time). Para definir um fuso horário que inclua ajustes para o horário de verão, use o TimeZoneInfo.CreateCustomTimeZone ou o TimeZoneInfo.CreateCustomTimeZone método.To define a time zone that includes adjustments for daylight saving time, use either the TimeZoneInfo.CreateCustomTimeZone or the TimeZoneInfo.CreateCustomTimeZone method.
A tabela a seguir mostra a relação entre os parâmetros que são fornecidos para o TimeZoneInfo.CreateCustomTimeZone método e as propriedades do TimeZoneInfo objeto que são retornados pela chamada de método.The following table shows the relationship between the parameters that are provided to the TimeZoneInfo.CreateCustomTimeZone method and the properties of the TimeZoneInfo object that are returned by the method call.
| Parâmetro CreateCustomTimeZoneCreateCustomTimeZone parameter | Propriedade TimeZoneInfoTimeZoneInfo property |
|---|---|
id |
Id |
baseUtcOffset |
BaseUtcOffset |
displayName |
DisplayName |
standardDisplayName |
StandardName |
Normalmente, o nome do horário padrão do fuso horário e seu identificador são os mesmos.Typically, the time zone's standard time name and its identifier are the same. No entanto, o comprimento do identificador do fuso horário não deve exceder 32 caracteres.However, the length of the time zone's identifier should not exceed 32 characters. A cadeia de caracteres passada para o displayName parâmetro segue um formato bastante padrão.The string passed to the displayName parameter follows a fairly standard format. A primeira parte do nome de exibição é o deslocamento base do fuso horário do Tempo Universal Coordenado, que é indicado pelo acrônimo GMT (Hora de Greenwich), entre parênteses.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. Isso é seguido por uma cadeia de caracteres que identifica o próprio fuso horário ou uma ou mais cidades, regiões ou países no fuso horário, ou ambos.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. Por exemplo:For example:
(GMT+02:00) Athens, Beirut, Istanbul, Minsk
(GMT-02:00) Mid-Atlantic
(GMT-07:00) Mountain Time (US & Canada)
Aplica-se a
CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[])
Cria um fuso horário personalizado com um identificador especificado, um deslocamento do UTC (Tempo Universal Coordenado), um nome de exibição, um nome de hora padrão e um nome e regras do horário de verão.Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, a standard time name, a daylight saving time name, and daylight saving time rules.
public:
static TimeZoneInfo ^ CreateCustomTimeZone(System::String ^ id, TimeSpan baseUtcOffset, System::String ^ displayName, System::String ^ standardDisplayName, System::String ^ daylightDisplayName, cli::array <TimeZoneInfo::AdjustmentRule ^> ^ adjustmentRules);
public static TimeZoneInfo CreateCustomTimeZone (string id, TimeSpan baseUtcOffset, string? displayName, string? standardDisplayName, string? daylightDisplayName, TimeZoneInfo.AdjustmentRule[]? adjustmentRules);
public static TimeZoneInfo CreateCustomTimeZone (string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string daylightDisplayName, TimeZoneInfo.AdjustmentRule[] adjustmentRules);
static member CreateCustomTimeZone : string * TimeSpan * string * string * string * TimeZoneInfo.AdjustmentRule[] -> TimeZoneInfo
Public Shared Function CreateCustomTimeZone (id As String, baseUtcOffset As TimeSpan, displayName As String, standardDisplayName As String, daylightDisplayName As String, adjustmentRules As TimeZoneInfo.AdjustmentRule()) As TimeZoneInfo
Parâmetros
- id
- String
O identificador do fuso horário.The time zone's identifier.
- baseUtcOffset
- TimeSpan
Um objeto que representa a diferença de horas entre esse fuso horário e o UTC (Horário Universal Coordenado).An object that represents the time difference between this time zone and Coordinated Universal Time (UTC).
- displayName
- String
O nome de exibição do novo fuso horário.The display name of the new time zone.
- standardDisplayName
- String
O nome da hora padrão do novo fuso horário.The new time zone's standard time name.
- daylightDisplayName
- String
O nome do horário de versão do novo fuso horário.The daylight saving time name of the new time zone.
- adjustmentRules
- TimeZoneInfo.AdjustmentRule[]
Uma matriz que aumenta a diferença UTC de base para um período específico.An array that augments the base UTC offset for a particular period.
Retornos
Um objeto TimeZoneInfo que representa o novo fuso horário.A TimeZoneInfo object that represents the new time zone.
Exceções
O parâmetro id é null.The id parameter is null.
O parâmetro id é uma cadeia de caracteres vazia ("").The id parameter is an empty string ("").
- ou --or-
O parâmetro baseUtcOffset não representa um número inteiro de minutos.The baseUtcOffset parameter does not represent a whole number of minutes.
O parâmetro baseUtcOffset é maior que 14 horas ou menor que -14 horas.The baseUtcOffset parameter is greater than 14 hours or less than -14 hours.
As regras de ajuste especificadas no parâmetro adjustmentRules se sobrepõem.The adjustment rules specified in the adjustmentRules parameter overlap.
- ou --or-
As regras de ajuste especificadas no parâmetro adjustmentRules não estão em ordem cronológica.The adjustment rules specified in the adjustmentRules parameter are not in chronological order.
- ou --or-
Um ou mais elementos em adjustmentRules são null.One or more elements in adjustmentRules are null.
- ou --or- Uma data pode ter várias regras de ajuste aplicadas a ela.A date can have multiple adjustment rules applied to it.
- ou --or-
A soma do parâmetro baseUtcOffset e do valor DaylightDelta de um ou mais objetos na matriz adjustmentRules é maior que 14 horas ou menor que -14 horas.The sum of the baseUtcOffset parameter and the DaylightDelta value of one or more objects in the adjustmentRules array is greater than 14 hours or less than -14 hours.
Exemplos
O exemplo a seguir cria um fuso horário personalizado para a estação Palmer e a ilha Anvers na Antártica.The following example creates a custom time zone for the Palmer station and Anvers Island in Antarctica. Em seguida, ele converte a hora local para a hora no novo fuso horário e exibe o resultado.It then converts the local time to the time in the new time zone and displays the result.
// Define transition times to/from DST
TimeZoneInfo.TransitionTime startTransition, endTransition;
startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 4, 0, 0),
10, 2, DayOfWeek.Sunday);
endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 3, 0, 0),
3, 2, DayOfWeek.Sunday);
// Define adjustment rule
TimeSpan delta = new TimeSpan(1, 0, 0);
TimeZoneInfo.AdjustmentRule adjustment;
adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1999, 10, 1), DateTime.MaxValue.Date, delta, startTransition, endTransition);
// Create array for adjustment rules
TimeZoneInfo.AdjustmentRule[] adjustments = {adjustment};
// Define other custom time zone arguments
string displayName = "(GMT-04:00) Antarctica/Palmer Time";
string standardName = "Palmer Time";
string daylightName = "Palmer Daylight Time";
TimeSpan offset = new TimeSpan(-4, 0, 0);
TimeZoneInfo palmer = TimeZoneInfo.CreateCustomTimeZone(standardName, offset, displayName, standardName, daylightName, adjustments);
Console.WriteLine("The current time is {0} {1}",
TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, palmer),
palmer.StandardName);
' Define transition times to/from DST
Dim startTransition As TimeZoneInfo.TransitionTime = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(#04:00:00#, 10, 2, DayOfWeek.Sunday)
Dim endTransition As TimeZoneInfo.TransitionTime = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(#3:00:00#, 3, 2, DayOfWeek.Sunday)
' Define adjustment rule
Dim delta As TimeSpan = New TimeSpan(1, 0, 0)
Dim adjustment As TimeZoneInfo.AdjustmentRule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(#10/01/1999#, Date.MaxValue.Date, delta, startTransition, endTransition)
' Create array for adjustment rules
Dim adjustments() As TimeZoneInfo.AdjustmentRule = {adjustment}
' Define other custom time zone arguments
Dim DisplayName As String = "(GMT-04:00) Antarctica/Palmer Time"
Dim standardName As String = "Palmer Standard Time"
Dim daylightName As String = "Palmer Daylight Time"
Dim offset As TimeSpan = New TimeSpan(-4, 0, 0)
Dim palmer As TimeZoneInfo = TimeZoneInfo.CreateCustomTimeZone(standardName, offset, displayName, standardName, daylightName, adjustments)
Console.WriteLine("The current time is {0} {1}", _
TimeZoneInfo.ConvertTime(Date.Now, TimeZoneInfo.Local, palmer), _
palmer.StandardName)
Comentários
Essa sobrecarga do TimeZoneInfo.CreateCustomTimeZone método é adequada para a criação de um fuso horário que dá suporte ao horário de verão.This overload of the TimeZoneInfo.CreateCustomTimeZone method is suitable for creating a time zone that supports daylight saving time. Para definir um fuso horário que não dá suporte ao horário de verão, use o TimeZoneInfo.CreateCustomTimeZone ou o TimeZoneInfo.CreateCustomTimeZone método.To define a time zone that does not support daylight saving time, use either the TimeZoneInfo.CreateCustomTimeZone or the TimeZoneInfo.CreateCustomTimeZone method.
A tabela a seguir mostra a relação entre os parâmetros que são fornecidos para o TimeZoneInfo.CreateCustomTimeZone método e os membros do TimeZoneInfo objeto que são retornados pela chamada de método.The following table shows the relationship between the parameters that are provided to the TimeZoneInfo.CreateCustomTimeZone method and the members of the TimeZoneInfo object that are returned by the method call.
| Parâmetro CreateCustomTimeZoneCreateCustomTimeZone parameter | Membro TimeZoneInfoTimeZoneInfo member |
|---|---|
id |
Id |
baseUtcOffset |
BaseUtcOffset |
displayName |
DisplayName |
standardDisplayName |
StandardName |
daylightDisplayName |
DaylightName |
adjustmentRules |
Uma matriz de System.TimeZoneInfo.AdjustmentRule objetos retornada pelo GetAdjustmentRules método.An array of System.TimeZoneInfo.AdjustmentRule objects returned by the GetAdjustmentRules method. |
Normalmente, o nome do horário padrão do fuso horário e seu identificador são os mesmos.Typically, the time zone's standard time name and its identifier are the same. No entanto, o comprimento do identificador do fuso horário não deve exceder 32 caracteres.However, the length of the time zone's identifier should not exceed 32 characters. A cadeia de caracteres passada para o displayName parâmetro segue um formato bastante padrão.The string passed to the displayName parameter follows a fairly standard format. A primeira parte do nome de exibição é o deslocamento base do fuso horário do Tempo Universal Coordenado, que é indicado pelo acrônimo GMT (Hora de Greenwich), entre parênteses.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. Isso é seguido por uma cadeia de caracteres que identifica o próprio fuso horário ou uma ou mais cidades, regiões ou países no fuso horário, ou ambos.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. Por exemplo:For example:
(GMT+02:00) Athens, Beirut, Istanbul, Minsk
(GMT-02:00) Mid-Atlantic
(GMT-07:00) Mountain Time (US & Canada)
O baseUtcOffset parâmetro define o deslocamento do fuso horário personalizado do UTC (tempo Universal Coordenado) para todas as regras de ajuste do fuso horário.The baseUtcOffset parameter defines the custom time zone's offset from Coordinated Universal Time (UTC) for all of the time zone's adjustment rules. Em outras palavras, o TimeZoneInfo modelo de objeto pressupõe que o deslocamento do fuso horário do UTC seja constante durante toda a vida útil do fuso horário e que exista independentemente de regras de ajuste específicas.In other words, the TimeZoneInfo 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. Para refletir um fuso horário que alterou seu deslocamento do UTC, você deve criar um novo objeto de fuso horário.To reflect a time zone that has changed its offset from UTC, you must create a new time zone object.
As regras de ajuste de um fuso horário são definidas fazendo o seguinte:A time zone's adjustment rules are defined by doing the following:
Chamar o CreateFloatingDateRule ou o CreateFixedDateRule método para definir o tempo de transição inicial e final para cada regra de ajuste.Calling either the CreateFloatingDateRule or the CreateFixedDateRule method to define the starting and ending transition time for each adjustment rule.
Chamando o CreateAdjustmentRule método para cada regra de ajuste.Calling the CreateAdjustmentRule method for each adjustment rule.
Atribuindo as regras de ajuste a uma matriz que pode ser passada como o
adjustmentRulesparâmetro.Assigning the adjustment rules to an array that can be passed as theadjustmentRulesparameter.
Aplica-se a
CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[], Boolean)
Cria um fuso horário personalizado com um identificador especificado, um deslocamento do UTC (Tempo Universal Coordenado), um nome de exibição, um nome de hora padrão, um nome de horário de verão, regras de horário de verão e um valor que indica se o objeto retornado reflete as informações sobre horário de verão.Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, a standard time name, a daylight saving time name, daylight saving time rules, and a value that indicates whether the returned object reflects daylight saving time information.
public:
static TimeZoneInfo ^ CreateCustomTimeZone(System::String ^ id, TimeSpan baseUtcOffset, System::String ^ displayName, System::String ^ standardDisplayName, System::String ^ daylightDisplayName, cli::array <TimeZoneInfo::AdjustmentRule ^> ^ adjustmentRules, bool disableDaylightSavingTime);
public static TimeZoneInfo CreateCustomTimeZone (string id, TimeSpan baseUtcOffset, string? displayName, string? standardDisplayName, string? daylightDisplayName, TimeZoneInfo.AdjustmentRule[]? adjustmentRules, bool disableDaylightSavingTime);
public static TimeZoneInfo CreateCustomTimeZone (string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string daylightDisplayName, TimeZoneInfo.AdjustmentRule[] adjustmentRules, bool disableDaylightSavingTime);
static member CreateCustomTimeZone : string * TimeSpan * string * string * string * TimeZoneInfo.AdjustmentRule[] * bool -> TimeZoneInfo
Public Shared Function CreateCustomTimeZone (id As String, baseUtcOffset As TimeSpan, displayName As String, standardDisplayName As String, daylightDisplayName As String, adjustmentRules As TimeZoneInfo.AdjustmentRule(), disableDaylightSavingTime As Boolean) As TimeZoneInfo
Parâmetros
- id
- String
O identificador do fuso horário.The time zone's identifier.
- baseUtcOffset
- TimeSpan
Um objeto TimeSpan que representa a diferença de tempo entre esse fuso horário e o UTC (Tempo Universal Coordenado).A TimeSpan object that represents the time difference between this time zone and Coordinated Universal Time (UTC).
- displayName
- String
O nome de exibição do novo fuso horário.The display name of the new time zone.
- standardDisplayName
- String
O nome da hora padrão do novo fuso horário.The standard time name of the new time zone.
- daylightDisplayName
- String
O nome do horário de versão do novo fuso horário.The daylight saving time name of the new time zone.
- adjustmentRules
- TimeZoneInfo.AdjustmentRule[]
Uma matriz de objetos TimeZoneInfo.AdjustmentRule que aumenta o deslocamento base do UTC para um período específico.An array of TimeZoneInfo.AdjustmentRule objects that augment the base UTC offset for a particular period.
- disableDaylightSavingTime
- Boolean
true para descartar informações relacionadas ao horário de verão presentes no adjustmentRules com o novo objeto; caso contrário, false.true to discard any daylight saving time-related information present in adjustmentRules with the new object; otherwise, false.
Retornos
O novo fuso horário.The new time zone. Se o parâmetro disableDaylightSavingTime é true, o objeto retornado não tem nenhum dado de horário de verão.If the disableDaylightSavingTime parameter is true, the returned object has no daylight saving time data.
Exceções
O parâmetro id é null.The id parameter is null.
O parâmetro id é uma cadeia de caracteres vazia ("").The id parameter is an empty string ("").
- ou --or-
O parâmetro baseUtcOffset não representa um número inteiro de minutos.The baseUtcOffset parameter does not represent a whole number of minutes.
O parâmetro baseUtcOffset é maior que 14 horas ou menor que -14 horas.The baseUtcOffset parameter is greater than 14 hours or less than -14 hours.
As regras de ajuste especificadas no parâmetro adjustmentRules se sobrepõem.The adjustment rules specified in the adjustmentRules parameter overlap.
- ou --or-
As regras de ajuste especificadas no parâmetro adjustmentRules não estão em ordem cronológica.The adjustment rules specified in the adjustmentRules parameter are not in chronological order.
- ou --or-
Um ou mais elementos em adjustmentRules são null.One or more elements in adjustmentRules are null.
- ou --or- Uma data pode ter várias regras de ajuste aplicadas a ela.A date can have multiple adjustment rules applied to it.
- ou --or-
A soma do parâmetro baseUtcOffset e do valor DaylightDelta de um ou mais objetos na matriz adjustmentRules é maior que 14 horas ou menor que -14 horas.The sum of the baseUtcOffset parameter and the DaylightDelta value of one or more objects in the adjustmentRules array is greater than 14 hours or less than -14 hours.
Exemplos
O exemplo a seguir cria um fuso horário personalizado para a estação Palmer e a ilha Anvers na Antártica.The following example creates a custom time zone for the Palmer station and Anvers Island in Antarctica. Ele define o disableDaylightSavingTime parâmetro na chamada para o TimeZoneInfo.CreateCustomTimeZone método como true .It sets the disableDaylightSavingTime parameter in the call to the TimeZoneInfo.CreateCustomTimeZone method to true. Em seguida, ele exibe o nome do horário de Verão do novo fuso horário, se houver um, e o número de regras de ajuste para confirmar se o novo fuso horário não tem informações de horário de verão.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.
// Define transition times to/from DST
TimeZoneInfo.TransitionTime startTransition, endTransition;
startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 4, 0, 0),
10, 2, DayOfWeek.Sunday);
endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1,3, 0, 0),
3, 2, DayOfWeek.Sunday);
// Define adjustment rule
TimeSpan delta = new TimeSpan(1, 0, 0);
TimeZoneInfo.AdjustmentRule adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1999, 10, 1),
DateTime.MaxValue.Date, delta, startTransition, endTransition);
// Create array for adjustment rules
TimeZoneInfo.AdjustmentRule[] adjustments = {adjustment};
// Define other custom time zone arguments
string displayName = "(GMT-04:00) Antarctica/Palmer Time";
string standardName = "Palmer Standard Time";
string daylightName = "Palmer Daylight Time";
TimeSpan offset = new TimeSpan(-4, 0, 0);
// Create custom time zone without copying DST information
TimeZoneInfo palmer = TimeZoneInfo.CreateCustomTimeZone(standardName, offset, displayName, standardName,
daylightName, adjustments, true);
// Indicate whether new time zone//s adjustment rules are present
Console.WriteLine("{0} {1}has {2} adjustment rules.",
palmer.StandardName,
! (string.IsNullOrEmpty(palmer.DaylightName)) ? "(" + palmer.DaylightName + ") ": "" ,
palmer.GetAdjustmentRules().Length);
// Indicate whether new time zone supports DST
Console.WriteLine("{0} supports DST: {1}", palmer.StandardName, palmer.SupportsDaylightSavingTime);
' Define transition times to/from DST
Dim startTransition As TimeZoneInfo.TransitionTime = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(#04:00:00#, 10, 2, DayOfWeek.Sunday)
Dim endTransition As TimeZoneInfo.TransitionTime = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(#3:00:00#, 3, 2, DayOfWeek.Sunday)
' Define adjustment rule
Dim delta As TimeSpan = New TimeSpan(1, 0, 0)
Dim adjustment As TimeZoneInfo.AdjustmentRule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(#10/01/1999#, Date.MaxValue.Date, delta, startTransition, endTransition)
' Create array for adjustment rules
Dim adjustments() As TimeZoneInfo.AdjustmentRule = {adjustment}
' Define other custom time zone arguments
Dim displayName As String = "(GMT-04:00) Antarctica/Palmer Time"
Dim standardName As String = "Palmer Standard Time"
Dim daylightName As String = "Palmer Daylight Time"
Dim offset As TimeSpan = New TimeSpan(-4, 0, 0)
Dim palmer As TimeZoneInfo = TimeZoneInfo.CreateCustomTimeZone(standardName, offset, displayName, standardName, daylightName, adjustments, True)
' Indicate whether new time zone's adjustment rules are present
Console.WriteLine("{0} {1}has {2} adjustment rules.", _
palmer.StandardName, _
IIf(Not String.IsNullOrEmpty(palmer.DaylightName), "(" & palmer.DaylightName & ") ", ""), _
palmer.GetAdjustmentRules().Length)
' Indicate whether new time zone supports DST
Console.WriteLine("{0} supports DST: {1}", palmer.StandardName, palmer.SupportsDaylightSavingTime)
Comentários
Você pode usar essa sobrecarga do TimeZoneInfo.CreateCustomTimeZone método para criar um fuso horário personalizado cujo suporte para horário de Verão pode ser determinado por condições em tempo de execução.You can use this overload of the TimeZoneInfo.CreateCustomTimeZone method to create a custom time zone whose support for daylight saving time can be determined by conditions at run time.
A tabela a seguir mostra a relação entre os parâmetros que são fornecidos para o TimeZoneInfo.CreateCustomTimeZone método e os membros do TimeZoneInfo objeto que são retornados pela chamada de método.The following table shows the relationship between the parameters that are provided to the TimeZoneInfo.CreateCustomTimeZone method and the members of the TimeZoneInfo object that are returned by the method call.
| Parâmetro CreateCustomTimeZoneCreateCustomTimeZone parameter | Propriedade TimeZoneInfoTimeZoneInfo property |
|---|---|
id |
Id |
baseUtcOffset |
BaseUtcOffset |
displayName |
DisplayName |
standardDisplayName |
StandardName |
daylightDisplayName |
DaylightName Se disableDaylightSavingTime for false ; String.Empty se disableDaylightSavingTime for true .DaylightName if disableDaylightSavingTime is false; String.Empty if disableDaylightSavingTime is true. |
adjustmentRules |
Uma matriz de TimeZoneInfo.AdjustmentRule objetos retornada pelo GetAdjustmentRules método se disableDaylightSavingTime for false ; uma matriz vazia retornada pelo método, GetAdjustmentRules se disableDaylightSavingTime for true .An array of TimeZoneInfo.AdjustmentRule objects returned by the GetAdjustmentRules method if disableDaylightSavingTime is false; an empty array returned by the GetAdjustmentRules method if disableDaylightSavingTime is true. |
disableDaylightSavingTime |
Não SupportsDaylightSavingTime .Not SupportsDaylightSavingTime. |
Normalmente, o nome do horário padrão do fuso horário e seu identificador são os mesmos.Typically, the time zone's standard time name and its identifier are the same. No entanto, o comprimento do identificador do fuso horário não deve exceder 32 caracteres.However, the length of the time zone's identifier should not exceed 32 characters. A cadeia de caracteres passada para o displayName parâmetro segue um formato bastante padrão.The string passed to the displayName parameter follows a fairly standard format. A primeira parte do nome de exibição é o deslocamento base do fuso horário do Tempo Universal Coordenado, que é indicado pelo acrônimo GMT (Hora de Greenwich), entre parênteses.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. Isso é seguido por uma cadeia de caracteres que identifica o próprio fuso horário ou uma ou mais cidades, regiões ou países no fuso horário, ou ambos.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. Por exemplo:For example:
(GMT+02:00) Athens, Beirut, Istanbul, Minsk
(GMT-02:00) Mid-Atlantic
(GMT-07:00) Mountain Time (US & Canada)
As regras de ajuste de um fuso horário são definidas fazendo o seguinte:A time zone's adjustment rules are defined by doing the following:
Chamar o CreateFloatingDateRule ou o CreateFixedDateRule método para definir as regras de transição inicial e final para cada regra de ajuste.Calling either the CreateFloatingDateRule or the CreateFixedDateRule method to define the starting and ending transition rules for each adjustment rule.
Chamando o CreateAdjustmentRule método para cada regra de ajuste.Calling the CreateAdjustmentRule method for each adjustment rule.
Atribuindo as regras de ajuste a uma matriz que pode ser passada como o
adjustmentRulesparâmetro.Assigning the adjustment rules to an array that can be passed as theadjustmentRulesparameter.
Se disableDaylightSavingTime o parâmetro for false , a operação desse método será idêntica à TimeZoneInfo.CreateCustomTimeZone sobrecarga.If disableDaylightSavingTime parameter is false, the operation of this method is identical to the TimeZoneInfo.CreateCustomTimeZone overload. Se disableDaylightSavingTime for true , o objeto retornado não incluirá nenhuma regra de ajuste e uma DaylightName propriedade cujo valor é uma cadeia de caracteres vazia.If disableDaylightSavingTime is true, the returned object includes no adjustment rules and a DaylightName property whose value is an empty string.