.NET Framework Class Library
TimeZoneInfo..::.HasSameRules Method

Indicates whether the current object and another TimeZoneInfo object have the same adjustment rules.

Namespace:  System
Assembly:  System.Core (in System.Core.dll)
Syntax

Visual Basic (Declaration)
Public Function HasSameRules ( _
    other As TimeZoneInfo _
) As Boolean
Visual Basic (Usage)
Dim instance As TimeZoneInfo
Dim other As TimeZoneInfo
Dim returnValue As Boolean

returnValue = instance.HasSameRules(other)
C#
public bool HasSameRules(
    TimeZoneInfo other
)
Visual C++
public:
bool HasSameRules(
    TimeZoneInfo^ other
)
JScript
public function HasSameRules(
    other : TimeZoneInfo
) : boolean

Parameters

other
Type: System..::.TimeZoneInfo
A second TimeZoneInfo object to compare with the current TimeZoneInfo object.

Return Value

Type: System..::.Boolean
true if the two time zones have identical adjustment rules and an identical base offset; otherwise, false.
Exceptions

ExceptionCondition
ArgumentNullException

The other parameter is nullNothingnullptra null reference (Nothing in Visual Basic).

Remarks

Like the TimeZoneInfo..::.Equals(TimeZoneInfo) method, the HasSameRules method indicates whether two time zones have the same base offset (as defined by the BaseUtcOffset property) and the same adjustment rules. Unlike the TimeZoneInfo..::.Equals(TimeZoneInfo) method, HasSameRules does not compare time zone identifiers (as defined by the Id property).

Examples

Typically, a number of time zones defined in the registry 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.

Visual Basic
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
C#
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);
      }
   }
}
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5
See Also

Reference

Tags :


Page view tracker