TimeZone.GetUtcOffset(DateTime) Metodo
Definizione
Restituisce lo scostamento dall'ora UTC (Coordinated Universal Time) per l'ora locale specificata.Returns the Coordinated Universal Time (UTC) offset for the specified local time.
public:
abstract TimeSpan GetUtcOffset(DateTime time);
public abstract TimeSpan GetUtcOffset (DateTime time);
abstract member GetUtcOffset : DateTime -> TimeSpan
Public MustOverride Function GetUtcOffset (time As DateTime) As TimeSpan
Parametri
- time
- DateTime
Valore di data e ora.A date and time value.
Restituisce
Offset dell'ora UTC (Coordinated Universal Time) da time
.The Coordinated Universal Time (UTC) offset from time
.
Commenti
Questo metodo restituisce l'offset o la differenza tra il time
parametro e l'ora UTC (Coordinated Universal Time).This method returns the offset, or difference, between the time
parameter and Coordinated Universal Time (UTC). Ovvero:That is:
time
= UTC + offsettime
= UTC + offset
Il metodo interpreta il fuso orario di time
in base alla relativa Kind Proprietà.The method interprets the time zone of time
based on its Kind property. Se il valore della Kind proprietà è DateTimeKind.Local o DateTimeKind.Unspecified , il metodo restituisce l'offset del fuso orario locale.If the value of the Kind property is DateTimeKind.Local or DateTimeKind.Unspecified, the method returns the offset of the local time zone. Se il valore della Kind proprietà è DateTimeKind.Utc , il metodo restituisce un offset uguale a TimeSpan.Zero .If the value of the Kind property is DateTimeKind.Utc, the method returns an offset equal to TimeSpan.Zero.
Se il fuso orario locale osserva l'ora legale, GetUtcOffset applica la regola di rettifica corrente a time
quando determina l'offset del fuso orario locale.If the local time zone observes daylight saving time, GetUtcOffset applies the current adjustment rule to time
when determining the offset of the local time zone. Ovvero, l'offset restituito da GetUtcOffset riflette se time
rientra nell'ora solare o nell'ora legale del fuso orario.That is, the offset returned by GetUtcOffset reflects whether time
falls in the time zone's standard time or its daylight saving time.
Nota
Il GetUtcOffset metodo riconosce solo la regola di regolazione dell'ora legale corrente per il fuso orario locale.The GetUtcOffset method recognizes only the current daylight saving time adjustment rule for the local time zone. Di conseguenza, è garantito che venga restituito accuratamente l'offset UTC di un'ora locale solo durante il periodo in cui è attiva la regola di rettifica più recente.As a result, it is guaranteed to accurately return the UTC offset of a local time only during the period in which the latest adjustment rule is in effect. Se time
è un valore di data e ora cronologico soggetto a una regola di rettifica precedente, può restituire risultati non accurati.It may return inaccurate results if time
is a historic date and time value that was subject to a previous adjustment rule.
Il GetUtcOffset metodo corrisponde al TimeZoneInfo.GetUtcOffset metodo.The GetUtcOffset method corresponds to the TimeZoneInfo.GetUtcOffset method. Quando possibile, usare il TimeZoneInfo.GetUtcOffset metodo.Whenever possible, use the TimeZoneInfo.GetUtcOffset method.
Poiché il valore di data e ora rappresentato da time
e l'offset di questo valore rispetto a UTC non sono strettamente associati, un valore di data e ora locale o non specificato può restituire un valore di offset diverso quando viene eseguito in computer diversi o quando viene eseguito nello stesso computer in fusi orari diversi.Because the date and time value represented by time
and this value's offset from UTC are not tightly coupled, a local or unspecified date and time value can return a different offset value when run on different computers or when run on the same computer under different time zones. Se questo comportamento è indesiderato, usare DateTimeOffset invece un valore.If this behavior is undesirable, use a DateTimeOffset value instead. Il DateTimeOffset tipo di dati abbina strettamente un valore di data e ora con il relativo offset rispetto all'ora UTC.The DateTimeOffset data type tightly couples a date and time value with its offset from UTC.