TimeZoneInfo.HasSameRules(TimeZoneInfo) Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Указывает, имеют ли текущий объект и другой TimeZoneInfo объект те же правила корректировки.
public:
bool HasSameRules(TimeZoneInfo ^ other);
public bool HasSameRules(TimeZoneInfo other);
member this.HasSameRules : TimeZoneInfo -> bool
Public Function HasSameRules (other As TimeZoneInfo) As Boolean
Параметры
- other
- TimeZoneInfo
Второй объект для сравнения с текущим TimeZoneInfo объектом.
Возвращаемое значение
true Значение , если два часовых пояса имеют одинаковые правила корректировки и идентичное базовое смещение; falseв противном случае .
Исключения
Параметр other имеет значение null.
Примеры
Как правило, ряд часовых поясов, определенных в реестре в Windows и библиотеке ICU в Linux и macOS, имеют одинаковое смещение от координированного универсального времени (UTC) и одинаковых правил корректировки. В следующем примере отображается список этих часовых поясов в консоли.
ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
TimeZoneInfo[] timeZoneArray = new TimeZoneInfo[timeZones.Count];
timeZones.CopyTo(timeZoneArray, 0);
// Iterate array from top to bottom
for (int ctr = timeZoneArray.GetUpperBound(0); ctr >= 1; ctr--)
{
// Get next item from top
TimeZoneInfo thisTimeZone = timeZoneArray[ctr];
for (int compareCtr = 0; compareCtr <= ctr - 1; compareCtr++)
{
// Determine if time zones have the same rules
if (thisTimeZone.HasSameRules(timeZoneArray[compareCtr]))
{
Console.WriteLine("{0} has the same rules as {1}",
thisTimeZone.StandardName,
timeZoneArray[compareCtr].StandardName);
}
}
}
let timeZones = TimeZoneInfo.GetSystemTimeZones()
let timeZoneArray = Array.ofSeq timeZones
// Iterate array from top to bottom
for ctr = timeZoneArray.GetUpperBound 0 - 1 downto 0 do
// Get next item from top
let thisTimeZone = timeZoneArray[ctr]
for compareCtr = 0 to ctr - 1 do
// Determine if time zones have the same rules
if thisTimeZone.HasSameRules timeZoneArray[compareCtr] then
printfn $"{thisTimeZone.StandardName} has the same rules as {timeZoneArray[compareCtr].StandardName}"
Dim timeZones As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones()
Dim timeZoneArray(timeZones.Count - 1) As TimeZoneInfo
timeZones.CopyTo(timeZoneArray, 0)
'Dim arrayPtr As Integer = 1
' Iterate array from top to bottom
For ctr As Integer = timeZoneArray.GetUpperBound(0) To 1 Step -1
' Get next item from top
Dim thisTimeZone As TimeZoneInfo = timeZoneArray(ctr)
For compareCtr As Integer = 0 To ctr - 1
' Determine if time zones have the same rules
If thisTimeZone.HasSameRules(timeZoneArray(compareCtr)) Then
Console.WriteLine("{0} has the same rules as {1}", _
thisTimeZone.StandardName, _
timeZoneArray(compareCtr).StandardName)
End If
Next
Next
Комментарии
TimeZoneInfo.Equals(TimeZoneInfo) Как и метод, метод указывает, HasSameRules имеют ли два часовых пояса одинаковые базовые смещения (как определено BaseUtcOffset свойством) и те же правила корректировки. TimeZoneInfo.Equals(TimeZoneInfo) В отличие от метода, HasSameRules не сравнивает идентификаторы часовых поясов (как определено свойствомId).