Class TimeZoneInfoExtensions
- Namespace
- System
- Assembly
- Arc4u.dll
Provides a set of static methods extending the TimeZoneInfo class.
public static class TimeZoneInfoExtensions
- Inheritance
-
TimeZoneInfoExtensions
- Inherited Members
Remarks
The methods read the UTC offset of the time zone instead of its adjustment rules. The rules are not the same on every operating system: on Linux and macOS they are built from the IANA database and change every year, while Windows uses a few floating rules. The results are therefore the same on every operating system.
Methods
GetDaylightChanges(TimeZoneInfo, int)
Gets the start and the end of the daylight saving time of timeZone in year.
public static DaylightTime? GetDaylightChanges(this TimeZoneInfo timeZone, int year)
Parameters
timeZoneTimeZoneInfoThe time zone.
yearintThe year.
Returns
- DaylightTime
The daylight saving period, or null when the time zone does not both enter and leave the daylight saving time in
year. Start and End are wall-clock times of the time zone, read on a clock still showing the time before the change (02:00 and 03:00 in Brussels), with a Kind of Unspecified. In the southern hemisphere the daylight saving time ends before it starts again in the same year: End is then before Start.
Examples
var changes = TimeZoneInfo.FindSystemTimeZoneById("Europe/Brussels").GetDaylightChanges(2026);
// Start = 2026-03-29 02:00, End = 2026-10-25 03:00, Delta = 01:00
Exceptions
- ArgumentNullException
timeZoneis null.- ArgumentOutOfRangeException
yearis not between 1 and 9999.
GetTransitions(TimeZoneInfo, DateTimeOffset, DateTimeOffset)
Gets the changes of the UTC offset of timeZone between from and to.
public static IReadOnlyList<TimeZoneTransition> GetTransitions(this TimeZoneInfo timeZone, DateTimeOffset from, DateTimeOffset to)
Parameters
timeZoneTimeZoneInfoThe time zone.
fromDateTimeOffsetThe start of the period, inclusive.
toDateTimeOffsetThe end of the period, exclusive.
Returns
- IReadOnlyList<TimeZoneTransition>
The changes, in chronological order, at the precision of the second. The list is empty when
tois not afterfrom.
Examples
var brussels = TimeZoneInfo.FindSystemTimeZoneById("Europe/Brussels");
var changes = brussels.GetTransitions(new DateTimeOffset(2026, 1, 1, 0, 0, 0, TimeSpan.Zero),
new DateTimeOffset(2027, 1, 1, 0, 0, 0, TimeSpan.Zero));
// 2026-03-29 01:00 UTC (+01:00 to +02:00) and 2026-10-25 01:00 UTC (+02:00 to +01:00)
Exceptions
- ArgumentNullException
timeZoneis null.