C# TimeZoneInfo HasSameRules

Description

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

Syntax

TimeZoneInfo.HasSameRules has the following syntax.


public bool HasSameRules(
  TimeZoneInfo other
)

Parameters

TimeZoneInfo.HasSameRules has the following parameters.

  • other - A second object to compare with the current TimeZoneInfo object.

Returns

TimeZoneInfo.HasSameRules method returns true if the two time zones have identical adjustment rules and an identical base offset; otherwise, false.

Example


using System.Collections.ObjectModel;
using System;//  ww w  .  ja v a 2 s .  com
public class MainClass{
  public static void Main(String[] argv){  
    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);
          }
       }
    }
  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version